i tried to clear all data from the table inside my database, it was successfull, but the only problems is, everytime i pressed the clear button, it does clear all data but after that the application shows it has stopped
which part did i go wrong? below is my coding from my database:
public boolean deleteRow(long id) {
SQLiteDatabase db = helper.getWritableDatabase();
String where = data.UID + "=" + id;
return db.delete(data.TABLE_NAME, where, null) != 0;
}
public void DeleteAll(){
Cursor c = readEntry();
long id = c.getColumnIndexOrThrow(data.UID);
if (c.moveToFirst()) {
do {
deleteRow(c.getLong((int) id));
} while (c.moveToNext());
}
c.close();
return;
}
and code from the other java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showbmi);
initializeApp();
}
private void initializeApp(){
weightinputid = (EditText) findViewById(R.id.weightid);
heightinputid = (EditText) findViewById(R.id.heightid);
buttonBMI = (Button) findViewById(R.id.buttonBMI);
BMIfinal= (TextView) findViewById(R.id.BMIfinal);
BMIStatus = (TextView) findViewById(R.id.BMIstatus);
save = (Button) findViewById(R.id.button);
detail = (Button)findViewById(R.id.button1);
bb = (Button)findViewById(R.id.bb);
table_layout = (TableLayout) findViewById(R.id.tableLayout1);
data = new fitnessdatabase(this);
BuildTable();
bb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data.DeleteAll();
new MyAsync().execute();
}
});
private class MyAsync extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
table_layout.removeAllViews();
PD = new ProgressDialog(Showbmi.this);
PD.setTitle("Please Wait..");
PD.setMessage("Loading...");
PD.setCancelable(false);
PD.show();
}
@Override
protected Void doInBackground(Void... params) {
String weight = weightinputid.getText().toString();
String bmi = BMIfinal.getText().toString();
String status = BMIStatus.getText().toString();
String date1 = mDateText.getText().toString();
// inserting data
data.open();
// sqlcon.insertData(firstname, lastname);
long id = data.insertData(weight, bmi, status, date1);
BuildTable();
return null;
}
}
Aucun commentaire:
Enregistrer un commentaire