Skip to content

Instantly share code, notes, and snippets.

@serdoune
Created February 7, 2018 19:57
Show Gist options
  • Save serdoune/0dbc18f4f053b4aed45eb30476e13bdd to your computer and use it in GitHub Desktop.
Save serdoune/0dbc18f4f053b4aed45eb30476e13bdd to your computer and use it in GitHub Desktop.
EditText firstname,lastname;
TextView textView;
DB_Controller controller;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstname=(EditText)findViewById(R.id.firstname_input);
lastname=(EditText)findViewById(R.id.lastname_input);
textView=(TextView)findViewById(R.id.textView);
controller =new DB_Controller(this,"",null,1);
}
public void btn_click(View view) {
switch (view.getId()){
case R.id.btn_add:
try {
controller.insert_student(firstname.getText().toString(),lastname.getText().toString());
}catch (SQLiteException e){
Toast.makeText(MainActivity.this,"ALREDY EXIST",Toast.LENGTH_LONG).show();
}
break;
case R.id.btn_del:
controller.delete_student(firstname.getText().toString());
break;
case R.id.btn_update:
AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("ENTER NEW FIRSTNAME");
final EditText new_firstname=new EditText((this));
dialog.setView(new_firstname);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface,int i){
controller.update_student(firstname.getText().toString(),new_firstname.getText().toString());
}
});
dialog.show();
break;
case R.id.btn_show:
controller.list_all_student(textView);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment