MODifikaTOR18
@MODifikaTOR18
Сисадмин

Почему ListView некликабелен?

Создал ListView со своими адаптером и слоем. Запустил, заполнил лист элементами, но они оказались некликабельны. Свойство Clickable у листа положительное, слой содержит два TextView и один Switch (кликабельный/некликабельный - без разницы, и так и так пробовал). Как это исправить? Системные слои не подходят, но с ними всё в порядке.
Xml-код слоя:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="9"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="4"></LinearLayout>

            <TextView
                android:id="@+id/todo_head"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="3"
                android:gravity="bottom"
                android:text="Это всё"
                android:textColor="@android:color/black" />

        </LinearLayout>

        <Switch
            android:id="@+id/statement"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginEnd="0dp"
            android:layout_weight="1"
            android:clickable="false"
            android:gravity="right" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="22dp">

        <TextView
            android:id="@+id/todo_body"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="2dp"
            android:layout_marginTop="2dp"
            android:text="Будет выглядеть вот так"
            android:textColor="@android:color/black"
            android:textSize="12sp" />

    </LinearLayout>

</LinearLayout>
<!--столько layout'ов нужно для правильного расположения компонентов относительно друг друга-->


Xml-код листа:
<ListView
        android:id="@+id/list_todo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />

Если нужно больше сведений - говорите, кину всё что нужно для решения проблемы.
  • Вопрос задан
  • 208 просмотров
Пригласить эксперта
Ответы на вопрос 1
Rou1997
@Rou1997
В Adapter следует назначать обработчик на сам элемент, точнее его корневой View, в итоге к этому и приходится приходить.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы