ListView onItemClickListener does not work Android

不问归期 提交于 2019-11-29 16:05:20

onItemClicked is not called because of the Button, in your row. Add

android:descendantFocusability="blocksDescendants"

to the root of your single_request layout

In single_request layout you have focusable item like Button thats why onItemClick is not fired. set all focusable items focusability false.

code snippet for focusable item like button

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:clickable="false"
    android:text="Button" />

If you want to set onClick of those Buttons set it inside your CustomAdapter.

I have sane issue happen Instead of button try to use ImageView.

now your single_request_layout will like.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/boxSF1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/perfildefecto" />

        <RelativeLayout
            android:id="@+id/boxSF2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:orientation="vertical"
            android:padding="5dp" >

            <TextView
                android:id="@+id/textViewAmigoUsuario"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:paddingBottom="2dip"
                android:paddingLeft="5dp"
                android:paddingTop="6dip"
                android:textColor="#333"
                android:textSize="16sp"
                android:textStyle="bold" />


                <ImageView
                    android:id="@+id/btnEliminar"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/textViewSolicitud"
                    android:layout_marginTop="30dp"
                    android:background="@drawable/denegar"
                    android:max="100" />

                <ImageView
                    android:id="@+id/btnAgregar"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_alignBaseline="@+id/btnEliminar"
                    android:layout_alignBottom="@+id/btnEliminar"
                    android:layout_marginRight="24dp"
                    android:layout_toLeftOf="@+id/btnEliminar"
                    android:background="@drawable/aceptar"
                    android:max="100" />

                <TextView
                    android:id="@+id/textViewSolicitud"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:layout_below="@id/textViewAmigoUsuario"
                    android:layout_margin="10dp"
                    android:gravity="left"
                    android:text="@string/friend_request"
                    android:textColor="@color/AzulClaro" />

        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

I hope this will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!