SHARE
TWEET

Untitled

a guest Mar 19th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class AddTodoActivity extends AppCompatActivity {
  2.  
  3.     EditText title_et , id_et;
  4.     Button add_todo_btn;
  5.     private SharedPreferences preferences;
  6.     private SharedPreferences.Editor editor;
  7.     private boolean priority = false;
  8.  
  9.     @Override
  10.     protected void onCreate(Bundle savedInstanceState) {
  11.         super.onCreate(savedInstanceState);
  12.         setContentView(R.layout.activity_add_todo);
  13.  
  14.         preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  15.         editor = preferences.edit();
  16.  
  17.         title_et = findViewById(R.id.title_et);
  18.         id_et = findViewById(R.id.id_et);
  19.         add_todo_btn = findViewById(R.id.add_todo_btn);
  20.  
  21.         add_todo_btn.setOnClickListener(new View.OnClickListener() {
  22.             @Override
  23.             public void onClick(View v) {
  24.  
  25.                 addTodoToPrefs();
  26.                 finish();
  27.             }
  28.         });
  29.     }
  30.  
  31.     private void addTodoToPrefs() {
  32.  
  33.         editor.putString("title" , title_et.getText().toString().trim());
  34.         editor.putBoolean("priority" , priority);
  35.         editor.putInt("id" , Integer.parseInt(id_et.getText().toString()));
  36.  
  37.         editor.commit();
  38.  
  39.     }
  40.  
  41.     public void onRadioButtonClicked(View view){
  42.         boolean isChecked = ((RadioButton) view).isChecked();
  43.  
  44.         switch (view.getId()){
  45.             case R.id.low_rb : if(isChecked){
  46.  
  47.                                    priority = false;
  48.                                     }
  49.                                 break;
  50.  
  51.             case R.id.high_rb : if(isChecked){
  52.  
  53.                 priority = true;
  54.             }
  55.             break;
  56.  
  57.         }
  58.     }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top