Skip to content Skip to sidebar Skip to footer

Onitemclicklistener Doesn't Work On Listview

I have an activity with a ListView. ListView with custom views. I add OnItemClickLIstener to the ListView. and when i click on item, in result i see nothing. Activity with ListView

Solution 1:

By setting focusable objects in your row layout, you are preventing the ListView from getting the touch event.

This FrameLayout is consuming the touch event:

<FrameLayout 
    android:id="@+id/attach_container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:focusableInTouchMode="true" 
    android:focusable="false"/>

Remove the focusable settings so it looks like this:

<FrameLayout 
    android:id="@+id/attach_container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />

(You really should organize your XML so that is is readable, in Eclipse use Ctrl+Shift+F.)

Solution 2:

Make Focus for all components as follows :

   android:focusable="false"

   android:focusableInTouchMode="false"

Solution 3:

I guess you are not getting the item the right way. Try this:

int position = (int) adapterView.getSelectedItemId();
Log.i("Position:", Integer.toString(position));

Edit

Try this piece of code.

ListViewlv= (ListView)findViewById(R.id.chat_list);
lv.setOnItemClickListener(newOnItemClickListener(){
       @OverridepublicvoidonItemClick(AdapterView<?> parent, View v, int position, long id) { 

             intposition= (int) parent.getSelectedItemId();
             Log.i("Position:", Integer.toString(position));
       }
});

Post a Comment for "Onitemclicklistener Doesn't Work On Listview"