gpt4 book ai didi

android - ExpandableView中如何识别 'onClick view'并获取 'groupId'

转载 作者:行者123 更新时间:2023-11-29 18:06:55 24 4
gpt4 key购买 nike

从下面的代码(在 ExpandableView Adapter 中)我如何在单击图像 (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();
}
};

关于android - ExpandableView中如何识别 'onClick view'并获取 'groupId',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12967474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com