从 getTag 检索 class
Retrieving class from getTag
我在我的 ListView 适配器中设置了 convertView.setTag(cell);
,其中包含 ListCell class。每当我单击其中一个 Listview 项目时,我都试图用 getTag
检索 ListCell class。
在这种需要检索整个 class 的情况下,我将如何使用 getTag?
Activity - OnItemClick
this.GetAllCommentsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
//How would I retrieve the class here with getTag?
Dialogbox();
}
});
Class
private class ListCell {
private TextView comment;
private ImageView PostImage;
private TextView PostTitle;
private TextView submitdate;
private int commentID;
private TextView PostVotes;
private TextView commentCount;
private int CurrentVote = -1;
private ImageView PostUpvote;
private ImageView userIconBackground;
private ImageView userIcon;
private GradientDrawable backgroundGradient;
private int backgroundColor;
}
您很可能只是在寻找普通演员:
ListCell lc = (ListCell)arg1.getTag(); // where arg1 is your View quoted method
final Object tag = v.getTag();
if(null != tag && tag instanceOf YourClass){
YourClass instance = (YourClass)tag;
}
您也可以使用:
viewInstance.setTag(viewInstance.getId(), yourTagObject);
如果你的视图元素,然后通过 id 获取标签。
我在我的 ListView 适配器中设置了 convertView.setTag(cell);
,其中包含 ListCell class。每当我单击其中一个 Listview 项目时,我都试图用 getTag
检索 ListCell class。
在这种需要检索整个 class 的情况下,我将如何使用 getTag?
Activity - OnItemClick
this.GetAllCommentsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
//How would I retrieve the class here with getTag?
Dialogbox();
}
});
Class
private class ListCell {
private TextView comment;
private ImageView PostImage;
private TextView PostTitle;
private TextView submitdate;
private int commentID;
private TextView PostVotes;
private TextView commentCount;
private int CurrentVote = -1;
private ImageView PostUpvote;
private ImageView userIconBackground;
private ImageView userIcon;
private GradientDrawable backgroundGradient;
private int backgroundColor;
}
您很可能只是在寻找普通演员:
ListCell lc = (ListCell)arg1.getTag(); // where arg1 is your View quoted method
final Object tag = v.getTag();
if(null != tag && tag instanceOf YourClass){
YourClass instance = (YourClass)tag;
}
您也可以使用:
viewInstance.setTag(viewInstance.getId(), yourTagObject);
如果你的视图元素,然后通过 id 获取标签。