Advertisement
IrakliKardava

Untitled

Feb 22nd, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. public class ShowMedicineInfoActivity extends AppCompatActivity {
  2.  
  3.     @Override
  4.     protected void onCreate(Bundle savedInstanceState) {
  5.         super.onCreate(savedInstanceState);
  6.         this.setContentView(R.layout.activity_medicine_info);
  7.  
  8.         SQLiteDatabaseHelper sqLiteDatabaseHelper = SQLiteDatabaseHelper.getInstance();
  9.         Medicine medicie = sqLiteDatabaseHelper.getMedicineById(getIntent().getLongExtra("Id",0));
  10.  
  11.         EditText nameOfMedicine = (EditText) findViewById(R.id.name_Of_Medicine_Info_EditText);
  12.         nameOfMedicine.setText(medicie.getName());
  13.  
  14.         TextView descriptionOfMedicine = (TextView) findViewById(R.id.decsription_From_Medicin_Info_TextView);
  15.         descriptionOfMedicine.setText(medicie.getDescription());
  16.  
  17.         EditText barcodeOfMedicine = (EditText) findViewById(R.id.barcode_From_Medicine_Info_EditText);
  18.         barcodeOfMedicine.setText(medicie.getEAN());
  19.             // button memory allocation what <irakliKardawa@gmail.com>
  20.         Button deleteButton = (Button) findViewById(R.id.delete_Medicine_Info_Button);
  21.  
  22.         Button updateButton = (Button) findViewById(R.id.modify_Medicine_Info_Button);
  23.            
  24.             // button onClick method which is deleting choosen medicine
  25.         deleteButton.setOnClickListener(new View.OnClickListener() {
  26.             @Override
  27.             public void onClick(View view) {
  28.  
  29.                 AlertDialog.Builder builder = new AlertDialog.Builder(ShowMedicineInfoActivity.this);
  30.                 builder.setTitle("Usuń");
  31.                 builder.setMessage("Czy na pewno chcesz usunać lek?");
  32.                 builder.setPositiveButton("TAK", new DialogInterface.OnClickListener() {
  33.  
  34.                     public void onClick(DialogInterface dialog, int which) {
  35.                         // here in case of positive ansver program is closeing
  36.                         SQLiteDatabaseHelper.getInstance().deleteMedicine(getIntent().getLongExtra("Id", 0));
  37.                         startActivity(new Intent(ShowMedicineInfoActivity.this, ActivityMedicineList.class));
  38.                     }
  39.                 });
  40.                 builder.setNegativeButton("NIE", new DialogInterface.OnClickListener() {
  41.  
  42.                     @Override
  43.                     public void onClick(DialogInterface dialog, int which) {
  44.                         // Do nothing
  45.                         dialog.dismiss();
  46.                     }
  47.                 });
  48.  
  49.                 AlertDialog alert = builder.create();
  50.                 alert.show();
  51.             }
  52.         });
  53.  
  54.         updateButton.setOnClickListener(new View.OnClickListener() {
  55.             @Override
  56.             public void onClick(View view) {
  57.                 Intent intent = new Intent (ShowMedicineInfoActivity.this,EditMedicineFromActivity.class);
  58.  
  59.                 Long medicineId = getIntent().getLongExtra("Id", 0);
  60.                 intent.putExtra("Id",medicineId);
  61.  
  62.                 startActivity(intent);
  63.             }
  64.         });
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement