2015-06-10 42 views
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; 
} 

回答

1

我不知道如果我正確地理解你的問題,但是當你形容的話,我想你需要做的是找到R.layout.bay_items XML文件,並添加radion鼠標。雖然添加一個單選按鈕沒有多大意義,但也許你的意思是複選框或類似的東西。

相關問題