0
我想知道有沒有人可以幫助解決這個問題?將一個RadioButton添加到ListView中的itemView適配器中
下面的代碼是ListView適配器,以啓用一個單獨的itemView,其中一切正常。 Iam能夠使用此適配器顯示條形碼編號和由條形碼閱讀器在列表視圖中讀取的項目的時間。
我的問題是如何添加一個單選按鈕到每個項目?
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;
}