I have a ListView with some items and in each item there is a ImageButton for deleting this item.
The method for deleting the item is inside an ArrayAdapter which uses a view holder.
//ALERT DIALOG FOR DELETE
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Delete All?");
builder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which)
{
dialog.dismiss();
}
});
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
mHelper.deleteAll(gmid,true); //DELETE ITEM
remove(getItem(position)); //REMOVE ITEM FROM LIST
notifyDataSetChanged();
TextView txtGameCount = (TextView) ((Activity)getContext()).findViewById(R.id.txtGamesCount);
int GamesCount = mHelper.getGamesCount(tmid); //GET COUNT OF ITEMS
txtGameCount.setText(String.valueOf(GamesCount)); //SET TEXT WITH NEW NUMBER OF ITEMS
dialog.dismiss(); //CLOSE DIALOG
}
});
builder.show();
My problem is that the TextView for displaying the number of items is displaying "0" and not the actual count of items.
The count method is working while I am adding an item and it is the following:
public int getGamesCount(int id)
{
String countQuery = "SELECT * FROM " + TABLEG +" WHERE t_id="+ id +"";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
return cursor.getCount();
}
What I am doing wrong here?
thank you