본문 바로가기
android

ExpandableList에서 버튼을 클릭할 수 없습니다.

by codingcampus 2024. 10. 10.
반응형
SMALL

ExpandableList에서 group layout에 다음과 같이 버튼을 추가 했더니 버튼은 클릭이 되지만 group  클릭할 수 없는 경우가 있습니다. 

- list_group.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/listTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:textColor="@android:color/white"
            android:paddingTop="10dp"
            android:paddingBottom="10dp" />
        <Button
            android:layout_width="80dp"
            android:layout_height="60dp"
            android:layout_alignParentRight="true"
            android:text="Play" />
    </RelativeLayout>
</LinearLayout>

이런 경우 다음과 같이 xml 레이아웃에서 버튼 포커스를 false로 설정한 다음 기존 게시물을 기반으로 이를 변경하고 focusable을 false로 동적으로 설정했습니다

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/listTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:textColor="@android:color/white"
            android:paddingTop="10dp"
            android:paddingBottom="10dp" />
        <Button
            android:layout_width="80dp"
            android:layout_height="60dp"
            android:descendantFocusability="blocksDescendants"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_alignParentRight="true"
            android:text="Play" />
    </RelativeLayout>
</LinearLayout>



반응형
LIST