Guest User

Untitled

a guest
Jul 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import android.content.Context;
  2. import android.content.Intent;
  3. import android.content.SharedPreferences;
  4.  
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12.  
  13. public class AddContacts extends AppCompatActivity {
  14.  
  15. SharedPreferences sharedPreferences;
  16.  
  17. SharedPreferences.Editor editor;
  18.  
  19. Button registerbtn;
  20. EditText name1, num1, name2, num2, name3, num3;
  21. String emname1,emname2,emname3;
  22. int emnum1,emnum2,emnum3;
  23.  
  24. @Override
  25.  
  26. protected void onCreate(Bundle savedInstanceState) {
  27.  
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_addcontacts);
  30.  
  31.  
  32. sharedPreferences = this.getSharedPreferences("universe.sk.syndriveapp.addcontacts", Context.MODE_PRIVATE);
  33. editor = sharedPreferences.edit();
  34.  
  35. registerbtn= findViewById(R.id.registerbtn);
  36.  
  37. name1 = findViewById(R.id.name1);
  38. num1 = findViewById(R.id.num1);
  39.  
  40. name2 = findViewById(R.id.name2);
  41. num2 = findViewById(R.id.num2);
  42.  
  43. name3 = findViewById(R.id.name3);
  44. num3 = findViewById(R.id.num3);
  45.  
  46. registerbtn.setOnClickListener(new View.OnClickListener() {
  47. @Override
  48. public void onClick(View view) {
  49.  
  50. emname1 = name1.getText().toString();
  51. emnum1 = Integer.parseInt(num1.getText().toString());
  52. emname2 = name2.getText().toString();
  53. emnum2 = Integer.parseInt(num2.getText().toString());
  54. emname3 = name3.getText().toString();
  55. emnum3 = Integer.parseInt(num3.getText().toString());
  56.  
  57. if (emname1.isEmpty() || emname2.isEmpty() || emname3.isEmpty()){
  58. Toast.makeText(AddContacts.this,"Please fill all details!",Toast.LENGTH_SHORT).show();
  59. onClick(view);
  60. }
  61. else {
  62.  
  63. editor.putString("name1", emname1);
  64. editor.putInt("num1", emnum1);
  65. editor.putString("name2", emname2);
  66. editor.putInt("num2", emnum2);
  67. editor.putString("name3", emname3);
  68. editor.putInt("num3", emnum3);
  69.  
  70. editor.apply();
  71. Toast.makeText(AddContacts.this,"Registration Success",Toast.LENGTH_SHORT).show();
  72. startActivity(new Intent(AddContacts.this,NavigationActivity.class));
  73. }
  74.  
  75.  
  76. }});
  77.  
  78.  
  79. }
  80.  
  81. }
Add Comment
Please, Sign In to add comment