dater.setText(theday);
dater.setTag(1, theday);
dater.setTag(2, theday + "-" + themonth + "-" + theyear);
dater.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
notification(date_txt);
String day = v.getTag(1).toString();
date_txt.setText(day);
}
});
我正在使用settag(int key object tag)对textview执行set标记;和settag(键),但我得到的错误,我无法弄清楚任何想法,谢谢你
答案 0 :(得分:3)
dater.setText(theday);
List<String> data = new ArrayList<String>();
data.add(theday);
data.add(theday + "-" + themonth + "-" + theyear);
dater.setTag(data);
dater.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
notification(date_txt);
ViewHold holder=v.getTag
String day = ((List<String>)v.getTag()).get(1).toString();
date_txt.setText(day);
}
});
答案 1 :(得分:0)
您在settag(int key object tag);
中使用的密钥应为资源中声明的id
。
根据文件
Sets a tag associated with this view and a key. A tag can be used to mark a view in its
hierarchy and does not have to be unique within the hierarchy. Tags can also be used to
store data within a view without resorting to another data structure. **The specified key
should be an id declared in the resources of the application to ensure it is unique (see
the ID resource type). Keys identified as belonging to the Android framework or not
associated with any package will cause an IllegalArgumentException to be thrown.**
答案 2 :(得分:0)
这个答案非常有用
textView.setTag(new HoldsTwoObjs(obj1, obj2));
HoldsTwoObjs isTagClass=(HoldsTwoObjs)textView.getTag();