Android 如何识别';onClick视图';并获得';groupId';在可扩展视图中

Android 如何识别';onClick视图';并获得';groupId';在可扩展视图中,android,onclick,expandablelistview,onclicklistener,expandablelistadapter,Android,Onclick,Expandablelistview,Onclicklistener,Expandablelistadapter,根据下面的代码(在ExpandableView适配器中),单击图像(iv)后如何获取组id。 如果用户单击组列表,我希望像往常一样展开它,但是如果用户单击组列表中的图像,我希望调用一些其他操作,并且需要SampleGroup的id public View getGroupView(int groupPosition, boolean isExpanded, View converView, ViewGroup parent){ SampleGroup group = (SampleG

根据下面的代码(在ExpandableView适配器中),单击图像(iv)后如何获取组id。 如果用户单击组列表,我希望像往常一样展开它,但是如果用户单击组列表中的图像,我希望调用一些其他操作,并且需要SampleGroup的id

public View getGroupView(int groupPosition, boolean isExpanded, View converView, ViewGroup parent){

     SampleGroup group = (SampleGroup)getGroup(groupPosition);

     if(convertView == null){
          LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = layoutInflater.inflate(R.layout.list_group, null);
     }

     ImageView iv = (ImageView)convertView.findViewById(R.id.some_iv):
     TextView tv = (TextView)convertView.findViewById(R.id.some_tv);

     iv.setImageDrawable(group.getImage());
     iv.setOnClickListener(onClickLintener);
     tv.setText(group.getText());
}


OnClickListener onClickLintener = new OnClickListener() {
    @Override
    public void onClick(View v) {
        //How to get group id here???
    }
};

public class SampleGroup{
     private int id;
     private String name;
     private Drawable image;

     public SampleGroup(int id, String name, Drawable image){
          this.id = id;
          this.name = name;
          this.image = image;
     }

     public int getId(){
          return id;
     }

     public void setId(int id){
          this.id = id;
     }

     public String getName(){
          return name;
     }

     public void setName(String name){
          this.name = name
     }

     public Drawable getImage(){
          return image;
     }

     public void setImage(Drawable image){
          this.image = image
     }
}
试试这个:

public View getGroupView(int groupPosition, boolean isExpanded, View converView, ViewGroup parent){
  ......
  ImageView iv = (ImageView)convertView.findViewById(R.id.some_iv);
  iv.setTag(group.id);
}
然后

OnClickListener onClickLintener = new OnClickListener() {
  @Override
  public void onClick(View v) {
      //How to get group id here???
      int groupId = (Integer) v.getTag();
  }
};