@Override public void onClick(View arg0) { // TODO Auto-generated method stub if (etLectNum.getText().toString().length() == 0) { Dialog d = new Dialog(this); d.setTitle("Lecture Number cannot be empty!"); d.show(); } else { lecture_number = Integer.parseInt(etLectNum.getText().toString()); lecture_title = etLectTitle.getText().toString(); lecture_description = etLectDescription.getText().toString(); dbh = new DBHelper(this); if (getIntent().getExtras().getBoolean("Update")) { dbh.updateLecture( semSelected, courseSelected, lecture_number, lecture_title, lecture_description, ""); Toast.makeText( getApplicationContext(), "Lecture " + lecture_number + " updated successfully!", Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(getApplicationContext(), com.aakash.studentmanager.LectureList.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { Cursor rs = dbh.getLectureData(semSelected, courseSelected, lecture_number); rs.moveToFirst(); if (rs.isAfterLast() == true) { dbh.insertLecture( semSelected, courseSelected, lecture_number, lecture_title, lecture_description, ""); Toast.makeText( getApplicationContext(), "Lecture " + lecture_number + " added successfully!", Toast.LENGTH_SHORT) .show(); Intent intent = new Intent(getApplicationContext(), com.aakash.studentmanager.LectureList.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { Dialog d = new Dialog(this); d.setTitle("Duplicate Entry:"); TextView tv = new TextView(this); tv.setText("Lecture Number " + lecture_number + " already added!"); d.setContentView(tv); d.show(); } } dbh.close(); } }