【问题标题】:Adding a RadioButton to a itemView adapter within a ListView将 RadioButton 添加到 ListView 中的 itemView 适配器
【发布时间】:2015-06-10 13:47:23
【问题描述】:

不知道有没有人可以帮忙解决一下?

下面的这段代码是 ListView 适配器,用于启用所有工作正常的单个 itemView。 我能够使用此适配器显示条形码编号和条形码阅读器在 listView 中读取项目的时间。

我的问题是如何为每个项目添加一个单选按钮?

public View getView(int position, View convertView, ViewGroup parent) {
    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    Map<String, Object> result = arrayc.get(position);

    TextView txttime;
    TextView txtbarcode;


    View itemView = inflater.inflate(R.layout.bay_items, parent, false);



    txtbarcode = (TextView) itemView.findViewById(R.id.barcodelbl);
    txtbarcode.setTextColor(Color.BLUE);
    txttime = (TextView) itemView.findViewById(R.id.timelabel);
    txttime.setTextColor(Color.BLUE);

    if (result.get("warehouse").toString().equals("1")) {

        View warehouse = itemView.findViewById(R.id.bayscan);
        warehouse.setBackgroundColor(Color.YELLOW);
    }
    if (result.get("unknown").toString().equals("1")) {

        View warehouse = itemView.findViewById(R.id.bayscan);
        warehouse.setBackgroundColor(Color.RED);
        txtbarcode.setTextColor(Color.WHITE);
        txttime.setTextColor(Color.WHITE);

    }
    txtbarcode.setText(result.get("barcode").toString());
    txttime.setText(result.get("time").toString());

    return itemView;
}

【问题讨论】:

    标签: listview arraylist radio-button barcode selecteditem


    【解决方案1】:

    我不确定我是否正确理解了您的问题,但正如您所描述的那样,我认为您需要做的就是找到 R.layout.bay_items xml 文件并在其中添加一个单选按钮。虽然添加一个单选按钮没有多大意义,但也许你的意思是复选框或类似的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      • 2018-06-27
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多