package [Link].
sqlitedbapp;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].R;
public class MainActivity extends AppCompatActivity implements [Link]
{
EditText etStdntID, etStdntName, etStdntProg;
Button btAdd, btDelete, btSearch, btView;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etStdntID = (EditText)findViewById([Link]);
etStdntName = (EditText)findViewById([Link]);
etStdntProg = (EditText)findViewById([Link]);
btAdd = (Button)findViewById([Link]);
btDelete = (Button)findViewById([Link]);
btSearch = (Button)findViewById([Link]);
btView = (Button)findViewById([Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
db = openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
[Link]("CREATE TABLE IF NOT EXISTS student(stdnt_id VARCHAR, stdnt_name
VARCHAR, stdnt_prog VARCHAR);");
}
public void clearText() {
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
public void showMessage(String title, String message) {
Builder builder = new Builder(this);
[Link](true);
[Link](title);
[Link](message);
[Link]();
}
@Override
public void onClick(View view) {
if (view== btAdd) {
[Link]("INSERT INTO student VALUES ('"+[Link]() +
"','"+[Link]() + "','"+[Link]() + "');");
showMessage("Success", "Record added.");
clearText();
}
else if (view== btDelete) {
Cursor c=[Link]("SELECT * FROM student WHERE stdnt_id='" +
[Link]() + "'", null);
if ([Link]()) {
[Link]("DELETE FROM student WHERE
stdnt_id='"+[Link]() + "'");
showMessage("Success", "Record Deleted.");
clearText();
}
}
else if (view==btSearch) {
Cursor c=[Link]("SELECT * FROM student WHERE stdnt_id='" +
[Link]() + "'", null);
if ([Link]()) {
StringBuffer buffer = new StringBuffer();
[Link]("Name: "+[Link](1) + "\n");
[Link]("Program: " + [Link](2) + "\n\n");
showMessage("Student Details", [Link]());
}
}
else if (view==btView) {
Cursor c=[Link]("SELECT * FROM student", null);
if([Link]()==0) {
showMessage("Error", "No records found.");
return;
}
StringBuffer buffer = new StringBuffer();
while ([Link]()) {
[Link]("ID: "+[Link](0) + "\n");
[Link]("Name: "+[Link](1) + "\n");
[Link]("Program: " + [Link](2) + "\n\n");
}
showMessage("Student Details", [Link]());
}
}
}