【发布时间】:2015-07-03 05:03:18
【问题描述】:
我有一个对象列表,我将它们设置为查看并插入到布局中
但我不知道如何识别哪个对象的哪个视图
在我将其插入布局之前,是否可以向视图添加其他属性?
例如:
LayoutInflater inflater=LayoutInflater.from(this);
HashMap<String, String> hm=new HashMap<String, String>();
hm.put("key1", "value 1");
hm.put("key2", "value 2");
hm.put("key3", "value 3");
for(String key: hm.keySet())
{
View oneItem=inflater.inflate(R.layout.oneItem, linearlayout, false);
TextView tv=(TextView)oneItem.findViewById(R.id.value);
tv.setText(hm.get(key));
//Is there any something like this?
//oneItem.putExtra("id", key);
//oneItem.setAttribute("id", key);
linearlayout.addView(oneItem);
}
【问题讨论】:
-
为此使用了
setTag()和getTag()。
标签: android android-layout android-view layout-inflater