1

ListView:

<ListView android:id="@+id/list11" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:layout_weight="1" 
          android:cacheColorHint="#00000000"> 
</ListView>

custome.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/txt_groupname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="15dp"
        android:layout_weight="3"
        android:text="asdasd"
        android:textColor="@color/TextColor" />

    <ImageButton
        android:id="@+id/btn_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/delete_gp"
        android:focusable="false"
        android:focusableInTouchMode="false" />

</LinearLayout>

Activity.java:

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        long itemValue = listView.getItemIdAtPosition(position);
        Log.e("==>", "" + itemValue);
    }

});

When I click on the <ImageButton> it works fine, but when I click on <ListView> it does not work.

How can I solve this problem?

Aryan Beezadhur
  • 4,503
  • 4
  • 21
  • 42
ckpatel
  • 1,926
  • 4
  • 18
  • 34

3 Answers3

2

ImageButton takes focus when you click on list item

Add the below

android:descendantFocusability="blocksDescendants" 

to the root element in custome.xml

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

You will use this code and it will ask to cast the object you just put the casting after it will fine....

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        long itemValue = parent.getItemIdAtPosition(position);
        Log.e("==>", "" + itemValue);
    }

});
Naveen Kumar Kuppan
  • 1,424
  • 1
  • 10
  • 12
0

add android:clickable="true" in the textview and the imagebutton also

Aditya_Anand
  • 525
  • 7
  • 17