Shakeel Nasrullah Shakeel Nasrullah - 5 months ago 11
SQL Question

delete zero index of listview which populated from database Android

My Database class is this, when i call

deleteEntry
, it does not remove 0 index , this is database class method

public int deleteEntry(String id)
{
SQLiteDatabase db = dbHelper.getWritableDatabase();
//String id=String.valueOf(ID);
String where="ID=?";

int numberOFEntriesDeleted= db.delete("TIME", where, new String[]{id}) ;
Toast.makeText(context, "Number of Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}


this is my
onItemClickListener


list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Log.d("Clicked item id", " " + id);

// data.remove(id);
String row = (String.valueOf(id));
data.deleteEntry(row);

Answer

You can try like this:

//---deletes a particular entry---
public int deleteEntry(String id) 
{
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    return db.delete("TIME", "ID = " + id, null) ;
}

By the way, make sure "TIME" is your tablename and you also close the database.