M
M
MODifikaTOR2017-03-21 08:44:32
Android
MODifikaTOR, 2017-03-21 08:44:32

Why is ListView not clickable?

I created a ListView with my own adapter and layer. Launched, filled the sheet with elements, but they turned out to be non-clickable. The sheet's Clickable property is positive, the layer contains two TextViews and one Switch (clickable / non-clickable - it doesn't matter, I tried it anyway). How to fix it? System layers are not suitable, but they are all right.
Layer XML code:

<?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'ов нужно для правильного расположения компонентов относительно друг друга-->

Sheet xml code:
<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" />

If you need more information - say, I will throw everything you need to solve the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2017-03-21
@Rou1997

In the Adapter, you should assign a handler to the element itself, or rather its root View, as a result, this is what you have to come to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question