我想顯示配對藍牙設備的列表並讓用戶選擇一個。我試圖用單選按鈕創建一個雙行列表視圖(一行代表友好的設備名稱,另一行代表MAC地址)。Android:帶單選按鈕的雙行列表視圖,無法選擇項目
爲此我抄simple_list_item_2_single_choice.xml到我的項目,並創建我用下面的代碼列表視圖:
listView = new ListView(activity);
listView.setItemsCanFocus(false);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
ArrayAdapter<BluetoothDevice> listViewAdapter = new ArrayAdapter<BluetoothDevice>(activity,
R.layout.simple_list_item_2_single_choice, android.R.id.text1) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
text1.setText(getItem(position).getName());
text2.setText(getItem(position).getAddress());
return view;
}
};
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> devices = btAdapter.getBondedDevices();
// addAll() is not supported on APIs below 11
for (BluetoothDevice device : devices)
listViewAdapter.add(device);
listView.setAdapter(listViewAdapter);
這顯示列表我想要的方式,但我不能選擇任何項目(當我點擊一個項目時單選按鈕保持空白)。是什麼賦予了?