将 RadioButton 添加到 ListView 中的 itemView 适配器

Adding a RadioButton to a itemView adapter within a ListView

请问有没有人可以帮忙?

下面的这段代码是 ListView 适配器,用于启用单个 itemView,并且一切正常。 我能够使用此适配器显示条形码编号和条形码 reader 在 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;
}

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