类android.widget.SimpleExpandableListAdapter源码实例Demo

下面列出了怎么用android.widget.SimpleExpandableListAdapter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ui   文件: elvDemo2_Fragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	// Inflate the layout for this fragment
	View myView = inflater.inflate(R.layout.elvdemo2_fragment, container, false);
	
    // get the listview
       expListView = (ExpandableListView) myView.findViewById(R.id.lvExp2);
       prepareListData();
       
       listAdapter =  new SimpleExpandableListAdapter(
                       myContext,						    //context
                       listDataGroup,                  // group list in the form:  List<? extends Map<String, ?>>
                       R.layout.evl2_group_row,        // Group item layout XML.
                       new String[] { "Group Item" },  // the key of group item.   String[] groupFrom, 
                       new int[] { R.id.row_name },    // ID of each group item.-Data under the key goes into this TextView.  int[] groupTo
                       listDataChild,              // childData describes second-level entries. in the form List<? extends List<? extends Map<String, ?>>>
                       R.layout.evl2_child_row,             // Layout for sub-level entries(second level).
                       new String[] {"Sub Item A", "Sub Item B"},      // Keys in childData maps to display.
                       new int[] { R.id.grp_childA, R.id.grp_childB}     // Data under the keys above go into these TextViews.
                   );
      expListView.setAdapter( listAdapter );       // setting the adapter in the list.
    
       return myView;
}
 
源代码2 项目: ui   文件: elvDemo2_Fragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	// Inflate the layout for this fragment
	View myView = inflater.inflate(R.layout.elvdemo2_fragment, container, false);
	
    // get the listview
       expListView = (ExpandableListView) myView.findViewById(R.id.lvExp2);
       prepareListData();
       
       listAdapter =  new SimpleExpandableListAdapter(
                       myContext,						    //context
                       listDataGroup,                  // group list in the form:  List<? extends Map<String, ?>>
                       R.layout.evl2_group_row,        // Group item layout XML.
                       new String[] { "Group Item" },  // the key of group item.   String[] groupFrom, 
                       new int[] { R.id.row_name },    // ID of each group item.-Data under the key goes into this TextView.  int[] groupTo
                       listDataChild,              // childData describes second-level entries. in the form List<? extends List<? extends Map<String, ?>>>
                       R.layout.evl2_child_row,             // Layout for sub-level entries(second level).
                       new String[] {"Sub Item A", "Sub Item B"},      // Keys in childData maps to display.
                       new int[] { R.id.grp_childA, R.id.grp_childB}     // Data under the keys above go into these TextViews.
                   );
      expListView.setAdapter( listAdapter );       // setting the adapter in the list.
    
       return myView;
}
 
源代码3 项目: AndroidBleManager   文件: DeviceControlActivity.java
private void clearUI() {
    mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
    mGattUUID.setText(R.string.no_data);
    mGattUUIDDesc.setText(R.string.no_data);
    mDataAsArray.setText(R.string.no_data);
    mDataAsString.setText(R.string.no_data);
}
 
源代码4 项目: anvil-examples   文件: ExpandableListLayout.java
public ExpandableListLayout(Context c) {
    super(c);

    expanded = new boolean[GROUP.length];
    List<Map<String, String>> groupData = new ArrayList<>();
    List<List<Map<String, String>>> childData = new ArrayList<>();
    for (int i = 0; i < GROUP.length; i++) {
        Map<String, String> map = new HashMap<String, String>();
        groupData.add(map);
        map.put(NAME, GROUP[i]);

        List<Map<String, String>> children = new ArrayList<>();
        for (int j = 0; j < CHILD[i].length; j++) {
            Map<String, String> childMap = new HashMap<String, String>();
            children.add(childMap);
            childMap.put(NAME, CHILD[i][j]);
        }
        childData.add(children);
        expanded[i] = false;
    }

    mAdapter = new SimpleExpandableListAdapter(c, groupData,
            android.R.layout.simple_expandable_list_item_1,
            new String[] { NAME }, new int[] { android.R.id.text1 },
            childData, android.R.layout.simple_expandable_list_item_2,
            new String[] { NAME }, new int[] { android.R.id.text1 });
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edge_effect_expandablelistview_layout);

    //this comes from android samples
    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
    for (int i = 0; i < 20; i++) {
        Map<String, String> curGroupMap = new HashMap<String, String>();
        groupData.add(curGroupMap);
        curGroupMap.put(NAME, "Group " + i);
        curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");

        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
        for (int j = 0; j < 15; j++) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            children.add(curChildMap);
            curChildMap.put(NAME, "Child " + j);
            curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
        }
        childData.add(children);
    }

    // Set up our adapter
    ((EdgeEffectExpandableListView) findViewById(R.id.expandablelistview)).setAdapter(new SimpleExpandableListAdapter(
            this,
            groupData,
            android.R.layout.simple_expandable_list_item_1,
            new String[]{NAME, IS_EVEN},
            new int[]{android.R.id.text1, android.R.id.text2},
            childData,
            android.R.layout.simple_expandable_list_item_2,
            new String[]{NAME, IS_EVEN},
            new int[]{android.R.id.text1, android.R.id.text2}
    ));
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edge_effect_expandablelistview_layout);

    //this comes from android samples
    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
    for (int i = 0; i < 20; i++) {
        Map<String, String> curGroupMap = new HashMap<String, String>();
        groupData.add(curGroupMap);
        curGroupMap.put(NAME, "Group " + i);
        curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");

        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
        for (int j = 0; j < 15; j++) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            children.add(curChildMap);
            curChildMap.put(NAME, "Child " + j);
            curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
        }
        childData.add(children);
    }

    // Set up our adapter
    ((EdgeEffectExpandableListView) findViewById(R.id.expandablelistview)).setAdapter(new SimpleExpandableListAdapter(
            this,
            groupData,
            android.R.layout.simple_expandable_list_item_1,
            new String[]{NAME, IS_EVEN},
            new int[]{android.R.id.text1, android.R.id.text2},
            childData,
            android.R.layout.simple_expandable_list_item_2,
            new String[]{NAME, IS_EVEN},
            new int[]{android.R.id.text1, android.R.id.text2}
    ));
}
 
源代码7 项目: codeexamples-android   文件: ExpandableList3.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
    for (int i = 0; i < 20; i++) {
        Map<String, String> curGroupMap = new HashMap<String, String>();
        groupData.add(curGroupMap);
        curGroupMap.put(NAME, "Group " + i);
        curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
        
        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
        for (int j = 0; j < 15; j++) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            children.add(curChildMap);
            curChildMap.put(NAME, "Child " + j);
            curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
        }
        childData.add(children);
    }
    
    // Set up our adapter
    mAdapter = new SimpleExpandableListAdapter(
            this,
            groupData,
            android.R.layout.simple_expandable_list_item_1,
            new String[] { NAME, IS_EVEN },
            new int[] { android.R.id.text1, android.R.id.text2 },
            childData,
            android.R.layout.simple_expandable_list_item_2,
            new String[] { NAME, IS_EVEN },
            new int[] { android.R.id.text1, android.R.id.text2 }
            );
    setListAdapter(mAdapter);
}
 
private void clearUI() {
    mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
    mDataField.setText(R.string.no_data);
}
 
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);
}
 
源代码10 项目: BLE   文件: DeviceControlActivity.java
/**
 * 根据GATT服务显示该服务下的所有特征值
 *
 * @param gattServices GATT服务
 * @return
 */
private SimpleExpandableListAdapter displayGattServices(final List<BluetoothGattService> gattServices) {
    if (gattServices == null) return null;
    String uuid;
    final String unknownServiceString = getResources().getString(R.string.unknown_service);
    final String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
    final List<Map<String, String>> gattServiceData = new ArrayList<>();
    final List<List<Map<String, String>>> gattCharacteristicData = new ArrayList<>();

    mGattServices = new ArrayList<>();
    mGattCharacteristics = new ArrayList<>();

    // Loops through available GATT Services.
    for (final BluetoothGattService gattService : gattServices) {
        final Map<String, String> currentServiceData = new HashMap<>();
        uuid = gattService.getUuid().toString();
        currentServiceData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownServiceString));
        currentServiceData.put(LIST_UUID, uuid);
        gattServiceData.add(currentServiceData);

        final List<Map<String, String>> gattCharacteristicGroupData = new ArrayList<>();
        final List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        final List<BluetoothGattCharacteristic> charas = new ArrayList<>();

        // Loops through available Characteristics.
        for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            charas.add(gattCharacteristic);
            final Map<String, String> currentCharaData = new HashMap<>();
            uuid = gattCharacteristic.getUuid().toString();
            currentCharaData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownCharaString));
            currentCharaData.put(LIST_UUID, uuid);
            gattCharacteristicGroupData.add(currentCharaData);
        }

        mGattServices.add(gattService);
        mGattCharacteristics.add(charas);
        gattCharacteristicData.add(gattCharacteristicGroupData);
    }

    final 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});
    return gattServiceAdapter;
}
 
源代码11 项目: AndroidBleManager   文件: DeviceControlActivity.java
private void displayGattServices(final List<BluetoothGattService> gattServices) {
    if (gattServices == null) return;
    generateExportString(gattServices);

    String uuid = null;
    final String unknownServiceString = getResources().getString(R.string.unknown_service);
    final String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
    final List<Map<String, String>> gattServiceData = new ArrayList<>();
    final List<List<Map<String, String>>> gattCharacteristicData = new ArrayList<>();
    mGattCharacteristics = new ArrayList<>();

    // Loops through available GATT Services.
    for (final BluetoothGattService gattService : gattServices) {
        final Map<String, String> currentServiceData = new HashMap<>();
        uuid = gattService.getUuid().toString();
        currentServiceData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownServiceString));
        currentServiceData.put(LIST_UUID, uuid.substring(4,8));
        System.out.println("---service name:"+currentServiceData.get(LIST_NAME));
        System.out.println("---service uuid:" + uuid);
        gattServiceData.add(currentServiceData);

        final List<Map<String, String>> gattCharacteristicGroupData = new ArrayList<>();
        final List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        final List<BluetoothGattCharacteristic> charas = new ArrayList<>();

        // Loops through available Characteristics.
        for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            charas.add(gattCharacteristic);
            final Map<String, String> currentCharaData = new HashMap<>();
            uuid = gattCharacteristic.getUuid().toString();
            String property = getPropertyString(gattCharacteristic.getProperties());
            currentCharaData.put(LIST_NAME, GattAttributeResolver.getAttributeName(uuid, unknownCharaString));
            currentCharaData.put(LIST_UUID, uuid.substring(4,8)+" "+property);
            System.out.println("-----char name:" + currentCharaData.get(LIST_NAME));
            System.out.println("-----chat uuid:"+ uuid);
            gattCharacteristicGroupData.add(currentCharaData);
            for (BluetoothGattDescriptor gattDescriptor:gattCharacteristic.getDescriptors()){
                System.out.println("--------des name:" + gattDescriptor.getUuid());
                System.out.println("--------des uuid:" + gattDescriptor.getValue()+" "+gattDescriptor.getPermissions());
            }
        }

        mGattCharacteristics.add(charas);
        gattCharacteristicData.add(gattCharacteristicGroupData);
    }

    final 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);
    invalidateOptionsMenu();
}
 
private void clearUI() {
    mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
    mDataField.setText(R.string.no_data);
}
 
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);
}
 
源代码14 项目: GizwitsBLE   文件: DeviceControlActivity.java
private void clearUI() {
	mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
}
 
源代码15 项目: GizwitsBLE   文件: DeviceControlActivity.java
private void displayGattServices(List<BleGattService> 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<BleGattCharacteristic>>();

	// Loops through available GATT Services.
	for (BleGattService gattService : gattServices) {
		HashMap<String, String> currentServiceData = new HashMap<String, String>();
		uuid = gattService.getUuid().toString().toUpperCase();

		currentServiceData.put(LIST_NAME, Utils.BLE_SERVICES
				.containsKey(uuid) ? Utils.BLE_SERVICES.get(uuid)
				: unknownServiceString);
		currentServiceData.put(LIST_UUID, uuid);
		gattServiceData.add(currentServiceData);

		ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
		List<BleGattCharacteristic> gattCharacteristics = gattService
				.getCharacteristics();
		ArrayList<BleGattCharacteristic> charas = new ArrayList<BleGattCharacteristic>();

		// Loops through available Characteristics.
		for (BleGattCharacteristic gattCharacteristic : gattCharacteristics) {
			charas.add(gattCharacteristic);
			HashMap<String, String> currentCharaData = new HashMap<String, String>();
			uuid = gattCharacteristic.getUuid().toString().toUpperCase();
			currentCharaData
					.put(LIST_NAME,
							Utils.BLE_CHARACTERISTICS.containsKey(uuid) ? Utils.BLE_CHARACTERISTICS
									.get(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);
}
 
源代码16 项目: jessica   文件: DeviceControlActivity.java
private void clearUI() {
    mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
    mDataField.setText(R.string.no_data);
}
 
源代码17 项目: jessica   文件: DeviceControlActivity.java
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);
}
 
private void clearUI() {
      gattServicesList.setAdapter((SimpleExpandableListAdapter) null);
      dataField.setText(R.string.no_data);
heartRateField.setText(R.string.no_data);
intervalField.setText(R.string.no_data);
  }
 
private void clearUI() {
    mGattServicesList.setAdapter((SimpleExpandableListAdapter) null);
    mDataField.setText(R.string.no_data);
}
 
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();
        System.out.println("displayGattServices + uuid="+uuid);
        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);
}
 
 类所在包
 同包方法