【发布时间】:2015-01-18 16:06:06
【问题描述】:
我有一个 ExpandableListView。当我单击其中一个列表时,我有几个项目。
http://img15.hostingpics.net/pics/311437expandablelistview.png
有没有办法访问第一组中的第一项? 我有
private ExpandableListView mGattServicesList;
SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(...);
mGattServicesList.setAdapter(gattServiceAdapter);
我可以通过以下方式访问第一组:
mGattServicesList.getChildAt(0);
我现在想进入这个孩子的体内去拿东西,但我找不到路。
好的,这是我要执行此操作的功能:
private void displayGattServices(List<BluetoothGattService> gattServices) {
if (gattServices == null) return;
String uuid = null;
String unknownServiceString = getResources().getString(R.string.unknown_service);
String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData
= new ArrayList<ArrayList<HashMap<String, String>>>();
mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();
// Loops through available GATT Services.
for (BluetoothGattService gattService : gattServices) {
HashMap<String, String> currentServiceData = new HashMap<String, String>();
uuid = gattService.getUuid().toString();
currentServiceData.put(
LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString));
currentServiceData.put(LIST_UUID, uuid);
gattServiceData.add(currentServiceData);
ArrayList<HashMap<String, String>> gattCharacteristicGroupData =new ArrayList<HashMap<String, String>>();
List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();
// Loops through available Characteristics.
for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
charas.add(gattCharacteristic);
HashMap<String, String> currentCharaData = new HashMap<String, String>();
uuid = gattCharacteristic.getUuid().toString();
currentCharaData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));
currentCharaData.put(LIST_UUID, uuid);
gattCharacteristicGroupData.add(currentCharaData);
}
mGattCharacteristics.add(charas);
gattCharacteristicData.add(gattCharacteristicGroupData);
}
SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(
this,gattServiceData,android.R.layout.simple_expandable_list_item_2,
new String[] {LIST_NAME, LIST_UUID},new int[] { android.R.id.text1, android.R.id.text2 },
gattCharacteristicData, android.R.layout.simple_expandable_list_item_2,
new String[] {LIST_NAME, LIST_UUID},new int[] { android.R.id.text1, android.R.id.text2 }
);
mGattServicesList.setAdapter(gattServiceAdapter);
mGattServicesList.performItemClick(mGattServicesList.getChildAt(1), 1, mGattServicesList.getItemIdAtPosition(1));
}
执行点击是为了扩展group1,然后我想对里面的第二个项目执行点击。
提前谢谢你
【问题讨论】:
-
看看这个网址stackoverflow.com/questions/26914488/…如果你有问题请告诉我
-
感谢您的回复。问题是我的类已经在扩展 Activity 所以我不能实现方法 getChildView()..
标签: android android-listview expandablelistview