【问题标题】:How to setTag Button in ListView如何在 ListView 中设置标签按钮
【发布时间】:2012-05-11 06:12:18
【问题描述】:

我在 row.xml 文件中生成了按钮,因此它将创建与列表项相同的按钮数量 所以我想 setTag ListView 中的所有 Button 来 getTag 并从数据库中检索数据。

【问题讨论】:

    标签: android listview button


    【解决方案1】:

    假设您为 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()+"");
    
    }
    

    【讨论】:

    • 对不起,我是 android 的新手 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); 我应该把它放在哪里
    • 您可以编辑您的问题并添加 SimpleAdapter 的代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    • 2015-04-02
    相关资源
    最近更新 更多