문제

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?

도움이 되었습니까?

해결책

ImageButton takes focus when you click on list item

Add the below

android:descendantFocusability="blocksDescendants" 

to the root element in custome.xml

다른 팁

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);
    }

});

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top