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

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

📚 0
📅 2023-07-21

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>

이 글과 함께 연습해보세요

읽은 내용을 Play Lab에서 바로 실행해볼 수 있어요.

Coding Quest · 빈칸

두 숫자 곱하기

width와 height를 곱해 넓이를 구하세요.

바로 연습하기
Coding Quest · 빈칸

60점 이상 합격

score가 60 이상이면 합격을 출력하세요.

바로 연습하기
Coding Quest · 빈칸

and 조건 쓰기

age가 10 이상 13 이하이면 통과를 출력하세요.

바로 연습하기
Coding Quest · 빈칸

elif 사용하기

80점 이상이면 B를 출력하세요.

바로 연습하기
Coding Quest · 빈칸

target 찾기

target과 같은 값을 찾으면 found를 True로 바꾸세요.

바로 연습하기