I am working on a groceries list app to learn android, but I cannot seem to figure out how to get the items in the ListView to trigger the onClick event in the ItemClickListener that I set on the listview. The method renderList() is called from the onResume() method, which grabs the list of groceries from the database and fills the ListView. Why does this implementation not work; the toast does not display when I click the list_item?
The list_item is a CheckBox view.
@Override
protected void onResume() {
super.onResume();
renderList();
}
protected void renderList(){
try {
dbHelper = new DbHelper(getApplicationContext());
db = dbHelper.getReadableDatabase();
cursor = db.query(DbHelper.TABLE, null, null, null, null, null, DbHelper.C_ID + " DESC");
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, FROM, TO);
groceriesList = (ListView)findViewById(R.id.listView1);
groceriesList.setAdapter(adapter);
groceriesList.setOnItemClickListener(clickListen);
} catch (Exception e) {
Log.d(TAG, "RenderList Error: ",e);
}
}
private OnItemClickListener clickListen = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "pos: "+position, Toast.LENGTH_SHORT).show();
}
};
My guess is that you have items in your list rows that are focusable. I would look into setting this to false or in your binding of items, just set their xml attributes to android:focusable=”false”