1
從下面的代碼(在ExpandableView Adapter中)我點擊圖像(iv)後如何獲得組ID。 如果用戶點擊組列表,我想像往常一樣點擊它,但是如果用戶點擊組列表中的圖像,我想調用其他一些操作,並且需要SampleGroup的id。如何在ExpandableView中識別「onClick視圖」並獲取「groupId」
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
}
}