如何访问里面ExpandableListView项目? [英] How to access items inside ExpandableListView?

查看:235
本文介绍了如何访问里面ExpandableListView项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ExpandableListView。当我点击这些名单中的一个,我有几个项目。

I have an ExpandableListView. When I click on one of these lists, I have several items.

http://img15.hostingpics.net/pics/311437expandablelistview.png

有没有一种方法或不访问的第一个项目在第一组?
我有

Is there a way or not to access to the first item in the first group ? I have

private ExpandableListView mGattServicesList;

SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(...);

mGattServicesList.setAdapter(gattServiceAdapter);

我可以访问到所述第一组

I can access to the first group with :

mGattServicesList.getChildAt(0);

我想现在走这孩子里面得到的物品,但我不能找到一种方法。

I want to go now inside this child to get items but I can't find a way.

好吧,这里就是我想这样做的功能:

Alright here is the function where I want to do this :

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));

}

该执行的点击是让组1 extanded,那我想做一个执行点击里面的第二个项目。

The perform click is to get the group1 extanded, then I want to do a perform click to the 2nd item inside.

感谢您提前

推荐答案

首先请张贴适配器您正在使用
第二getchild功能应该得到groupPosition和childPosition。
好像你使用普通的列表,而不是适配器消耗之一。

First please post the adapter you are using second getchild function should get groupPosition and childPosition. it seems like you use regular list adapter instead of expendable one.

编辑:

我看你尝试通过列表从适配器我相信,这将解决您的问题,以获得该项目来代替。

I see you try to get the item via the list instead from the Adapter I believe this will solve your problem.

另外,我stronglly reccomend你做自定义适配器,而不是使用以防万一基本一你想要的任何变化

Also i am stronglly reccomend you to make custom adapter instead of use the basic one just in case you want any change

这篇关于如何访问里面ExpandableListView项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆