Невозможно щелкнуть дочерний элемент в расширенном представлении списка, когда я использую макет ограничения, тогда как с линейным макетом это работает правильно - PullRequest
0 голосов
/ 14 октября 2019

Я скопировал код для расширенного представления списка откуда-то в стеке, и он работал должным образом, я смог развернуть список и щелкнуть как родительский, так и дочерний элементы, но когда я добавил элемент check_box в макет, щелчок дочернего представления делаетбольше не работаетПожалуйста, помогите мне с этим, это очень странно, так как я просто добавляю один элемент флажка.

// does not work with when check box element is there
 <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/expandedListItem"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="63dp"
            android:layout_height="19dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="56dp"
            android:layout_marginRight="56dp"
            android:text="Available"
            app:layout_constraintBottom_toBottomOf="@+id/expandedListItem"
            app:layout_constraintEnd_toEndOf="@+id/expandedListItem"
            app:layout_constraintTop_toTopOf="@+id/expandedListItem"
            app:layout_constraintVertical_bias="0.0" />

        <CheckBox
            android:id="@+id/available"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:onClick="onCheckboxClicked"
            android:text=""
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@+id/expandedListItem"
            app:layout_constraintHorizontal_bias="0.829"
            app:layout_constraintStart_toEndOf="@+id/textView3"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />
    </android.support.constraint.ConstraintLayout>


//Here is the activity part where click methods have been written.
 expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
                @Override
                public void onGroupExpand(int groupPosition) {
                    Toast.makeText(getApplicationContext(),
                            expandableListTitle.get(groupPosition) + " List Expanded.",
                            Toast.LENGTH_SHORT).show();
                    Log.d("Expanded1", "Expanded");
                }
            });

            expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
                @Override
                public void onGroupCollapse(int groupPosition) {
                    Toast.makeText(getApplicationContext(),
                            expandableListTitle.get(groupPosition) + " List Collapsed.",
                            Toast.LENGTH_SHORT).show();
                }
            });

            expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView parent, View v,
                                            int groupPosition, int childPosition, long id) {
                    Log.d("Child Clicked", "Child Clicked");
                    Toast.makeText(
                            getApplicationContext(),
                            expandableListTitle.get(groupPosition)
                                    + " -> "
                                    + expandableListDetail.get(`enter code here`
                                    expandableListTitle.get(groupPosition)).get(
                                    childPosition), Toast.LENGTH_SHORT
                    ).show();

                    List<NameValuePair> params = new ArrayList<NameValuePair>();
                    params.add(new BasicNameValuePair("itemName", expandableListDetail.get(
                            expandableListTitle.get(groupPosition)).get(
                            childPosition)  ));
                    params.add(new BasicNameValuePair("available", "N"));
                    JSONParser jParser = new JSONParser();
                    jParser.hitURL(url, params);
                    Log.d("Update Stock-1", "Update");

                    return false;
                }
            });

Нажатие дочернего элемента представления должно было работать в обоих случаях, но при наличии флажка щелчок по дочернему элементу даже не распознается, метод expandableListView.setOnChildClickListener даже не вызывается .. ..

1 Ответ

0 голосов
/ 17 октября 2019

Вам нужно добавить android:focusable="false" для CheckBox

<CheckBox
    android:id="@+id/available"
    android:focusable="false"
      ....
 />
...