android.widget.SimpleExpandableListAdapter Java Examples
The following examples show how to use
android.widget.SimpleExpandableListAdapter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: elvDemo2_Fragment.java From ui with Apache License 2.0 | 6 votes |
@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; }
Example #2
Source File: elvDemo2_Fragment.java From ui with Apache License 2.0 | 6 votes |
@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; }
Example #3
Source File: ExpandableListViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@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} )); }
Example #4
Source File: ExpandableList3.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@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); }
Example #5
Source File: ExpandableListViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@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} )); }
Example #6
Source File: ExpandableListLayout.java From anvil-examples with MIT License | 5 votes |
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 }); }
Example #7
Source File: DeviceControlActivity.java From AndroidBleManager with Apache License 2.0 | 5 votes |
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); }
Example #8
Source File: DeviceControlActivity.java From android-BluetoothLeGatt with Apache License 2.0 | 4 votes |
private void clearUI() { mGattServicesList.setAdapter((SimpleExpandableListAdapter) null); mDataField.setText(R.string.no_data); }
Example #9
Source File: DeviceControlActivity.java From android-BluetoothLeGatt with Apache License 2.0 | 4 votes |
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); }
Example #10
Source File: DeviceControlActivity.java From AndroidBleManager with Apache License 2.0 | 4 votes |
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(); }
Example #11
Source File: DeviceControlActivity.java From connectivity-samples with Apache License 2.0 | 4 votes |
private void clearUI() { mGattServicesList.setAdapter((SimpleExpandableListAdapter) null); mDataField.setText(R.string.no_data); }
Example #12
Source File: DeviceControlActivity.java From BLE with Apache License 2.0 | 4 votes |
/** * 根据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; }
Example #13
Source File: DeviceControlActivity.java From GizwitsBLE with Apache License 2.0 | 4 votes |
private void clearUI() { mGattServicesList.setAdapter((SimpleExpandableListAdapter) null); }
Example #14
Source File: DeviceControlActivity.java From GizwitsBLE with Apache License 2.0 | 4 votes |
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); }
Example #15
Source File: DeviceControlActivity.java From jessica with MIT License | 4 votes |
private void clearUI() { mGattServicesList.setAdapter((SimpleExpandableListAdapter) null); mDataField.setText(R.string.no_data); }
Example #16
Source File: DeviceControlActivity.java From jessica with MIT License | 4 votes |
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); }
Example #17
Source File: DeviceServicesActivity.java From BLE-Heart-rate-variability-demo with MIT License | 4 votes |
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); }
Example #18
Source File: DeviceControlActivity.java From BlunoAccessoryShieldDemo with GNU General Public License v3.0 | 4 votes |
private void clearUI() { mGattServicesList.setAdapter((SimpleExpandableListAdapter) null); mDataField.setText(R.string.no_data); }
Example #19
Source File: DeviceControlActivity.java From BlunoAccessoryShieldDemo with GNU General Public License v3.0 | 4 votes |
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); }
Example #20
Source File: DeviceControlActivity.java From connectivity-samples with Apache License 2.0 | 4 votes |
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); }