当使用微调器作为expandablelistview中的组的子级时,OnChildClickListener不起作用

时间:2018-02-10 18:31:27

标签: java android android-layout clicklistener

我有一个Expandablelistview,其中我显示了子行,有两个微调器,一个edittext和一个图像按钮。我的要求是获取子节点的每个组件id并对这些组件进行一些操作。假设,当点击添加图标时,它应该将另一个子行添加到同一组。我已经花了差不多两天时间,没有得到任何解决方案或根本原因,为什么它以这种方式行事。请任何人有任何建议或想法,将不胜感激。

expandableListView.setOnChildClickListener(new OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long id) {
        Toast.makeText(getBaseContext()," Child is clicked." ,Toast.LENGTH_SHORT).show();
        return false;
    }
});

这是child_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ecf4ee"
    android:orientation="horizontal"
    tools:context="com.esspl.eportal.TimeEntryChildviewActivity">

    <ImageView
        android:id="@+id/addIconId"
        android:layout_width="25dp"
        android:layout_height="20dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="7dp"
        android:layout_marginTop="7dp"
        android:background="@drawable/add_icon" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="50dp"
        android:layout_height="33dp"
        android:layout_alignBottom="@+id/devTypeId"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="18dp"
        android:layout_marginRight="20dp"
        android:layout_toEndOf="@+id/devTypeId"
        android:layout_toRightOf="@+id/devTypeId"
        android:background="#e2f70a"
        android:gravity="start"
        android:hint="0.00"
        android:inputType="numberDecimal"
        android:nextFocusRight="@drawable/add_icon"
        android:textAlignment="textStart" />

    <Spinner
        android:id="@+id/devTypeId"
        android:layout_width="100dp"
        android:layout_height="35dp"
        android:layout_alignParentTop="false"
        android:layout_toEndOf="@+id/projectTypeId"
        android:layout_toRightOf="@+id/projectTypeId"
        android:layout_weight="1"
        android:entries="@array/development_type"
        android:layoutDirection="ltr" />

    <Spinner
        android:id="@+id/projectTypeId"
        android:layout_width="100dp"
        android:layout_height="35dp"
        android:layout_marginRight="18dp"
        android:layout_weight="1"
        android:dropDownHorizontalOffset="15dp"
        android:entries="@array/project_type"
        android:layoutDirection="ltr" />

    enter code here

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

  the onChildClikListener was not getting called because of this code 
           android:entries="@array/development_type" ,

从中删除上述行代码 微调器为我工作。但是如何在后端动态地设置值到微调器而不是使用ArrayAdapter。我猜是,array是expandablelistview中spinner的问题,但不确定。