gujjula nikhilreddy gujjula nikhilreddy - 6 months ago 37
Android Question

ListView with OnItemClickListener android

I am using a custom

with
RatingBar
and
ImageButton
. Here is my problem: When I click on my
ListView
, my
OnItemClickListener
is not working. Please can any one help me.
Code:

ListView lv = getListView();
setContentView(lv);
lv.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
{
Toast.makeText(SuggestionActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});


Thanks in advance!

Answer Source

Though a very old question, but I am still posting an answer to it so that it may help some one. If you are using any layout inside the list view then use ...

android:descendantFocusability="blocksDescendants"    

... on the first parent layout inside the list. This works as magic the click will not be consumed by any element inside the list but will directly go to the list item.