Adding a RadioButton to a itemView adapter within a ListView

72 views Asked by At

I wonder if anyone can help with this , please?

This Code below is ListView adapter to enable a single itemView to which all works well. Iam able to show with this adapter the barcode number and the time of the item that is read by a barcode reader with in a listView.

My question is how to add a Radio Button to each item ?

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

There are 1 answers

0
Stefan Bogaard On BEST ANSWER

I'm not sure if I understand your question correctly but as you describe it, I think all you need to do is locate the R.layout.bay_items xml file and add a radion button there. Although it doesn't make much sense to add one radio button, but perhaps you mean checkbox or something like that.