如何在 android 中映射变量和视图?

How to map variable and view in android?

我有一个对象列表,我将它们设置为查看并插入布局

但我不知道如何识别哪个对象的哪个视图

在我将它插入到布局之前,是否可以添加额外的属性来查看?

例如:

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);
}
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));

    oneItem.setTag(hm.get(key));

    linearlayout.addView(oneItem);
}

现在只要你找到那个项目,你就可以找到类似的东西

View view=linearlayout.getTag(hm.get(key));