如何在Android中为Expandablelistview中的组项目实现不同的ClickListener?

如何在Android中为Expandablelistview中的组项目实现不同的ClickListener?,android,expandablelistview,Android,Expandablelistview,因此,我的expandablelistview看起来像(抱歉,我不能发布图像,因为我的声誉不足10)。在组项目布局文件中,我有一个textview和一个imageview,如下所示: Textview Imageview(info icon) Textview Imageview(info icon) 我想要的是点击右边的信息图标,它会显示toast几秒钟,给出关于这个组的信息&如果我点击textview,它会展开,并在下面正常显示子项 我的2个布局文件如下所示

因此,我的expandablelistview看起来像(抱歉,我不能发布图像,因为我的声誉不足10)。在组项目布局文件中,我有一个textview和一个imageview,如下所示:

Textview         Imageview(info icon)
Textview         Imageview(info icon)
我想要的是点击右边的信息图标,它会显示toast几秒钟,给出关于这个组的信息&如果我点击textview,它会展开,并在下面正常显示子项

我的2个布局文件如下所示: Mainlayout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

      <ExpandableListView
          android:id="@+id/lvexp"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:groupIndicator="@null"
          android:background="@drawable/back">
     </ExpandableListView>

</RelativeLayout>

GroupLayout.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:orientation="horizontal" >

<TextView
    android:id="@+id/lblheader"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:text="Large Text"
    android:layout_weight="1.0"
    android:gravity="center"
    android:paddingTop="12dp"
    android:paddingBottom="12dp"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#24B9FF" />

<ImageView
    android:id="@+id/help_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/info_icon"
    android:layout_weight=".1"
     android:paddingTop="12dp"
     android:clickable="true"
    android:paddingBottom="12dp" />

如何处理单击imageview以显示toast。我已经实现了onGroupClick&我可以在单击时展开组。但是如何实现imageview的单击侦听器


请提供帮助。除了在应用程序中使用Expandablelistview,我没有其他选择。

如何将此
groupLayout xml
附加到适配器。实际上,您必须在
ExpandableListAdapter
中实现方法
getGroupView()
。在那里,您可以展开此布局,访问此布局中的所有视图,并为此布局编写单击侦听器

好的..这是实现clicklisteners的示例getGroupView(),供您参考:

@Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            View v = convertView;
            if(v == null){
                v= mInflator.inflate(R.layout.group_layout, null);
            }

            TextView text = (TextView )v.findViewById(R.id.your text id);
            ImageView image = (ImageView)v.findViewById(R.id.your image id);


          text .setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            ///your code here
       }
        }
    });



       image .setOnClickListener(new OnClickListener() {
            @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            ///your code here
       }
        }
    });

            return v;
        }

伙计,我正在做你想说的。我刚刚在这里展示了grouplayout xml,因为我想展示我的组项目的外观。你能告诉我如何分别为textview和imageview编写click listeners。我已经编辑了答案,显示了为你的视图编写clickListeners的代码……谢谢,伙计。但是自从我所有的textview和imageview来自单个xml(请参见我的Grouplayout.xml)。因此,每个视图都具有相同的id,因此我如何知道哪个imageview(在哪个行下单击)。如果我用愚蠢的问题来打扰您,很抱歉。感谢您的帮助。嘿,我们都是来打扰您的……好的。.每个getGroupView()都会给您参数“int groupPosition”因此,您可以跟踪使用此参数单击的行。