【发布时间】:2012-05-11 06:12:18
【问题描述】:
我在 row.xml 文件中生成了按钮,因此它将创建与列表项相同的按钮数量 所以我想 setTag ListView 中的所有 Button 来 getTag 并从数据库中检索数据。
【问题讨论】:
我在 row.xml 文件中生成了按钮,因此它将创建与列表项相同的按钮数量 所以我想 setTag ListView 中的所有 Button 来 getTag 并从数据库中检索数据。
【问题讨论】:
假设您为 ListView 使用自定义适配器,您将能够在适配器的 getView() 中为每个按钮设置标签,
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
convertView = inflaterObject.inflate(R.layout.row,parent,false);
Button tagButton=(Button)convertView.findviewbyId(R.id.buttonID);
tagButton.setTag(pos);
//To fetch the button Tag
Log.i("Button Tab at Pos "+pos,tagButton.getTag()+"");
}
【讨论】:
for(InQueueAdapter q:queue) { map = new HashMap<string string>(); map.put("id", Integer.toString(q.getID())); map.put("数量",q.getAm()); mylist.add(地图); } SimpleAdapter ms = new SimpleAdapter(this, mylist, R.layout.data_row , new String[] {"id","amount"}, new int[] {R.id.idCell,R.id.amountCell}); list.setAdapter(ms); 我应该把它放在哪里