当我使用约束布局时无法在展开的列表视图中单击子级,而使用线性布局则可以正常工作

问题描述 投票:0回答:1

我已经从堆栈中的某处复制了扩展列表视图的代码,并且可以正常工作,我能够扩展列表并单击父级和子级,但是当我将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方法。...

android android-linearlayout expandablelistview android-constraintlayout onitemclicklistener
1个回答
0
投票

您需要为android:focusable="false"添加CheckBox

© www.soinside.com 2019 - 2024. All rights reserved.