Widget - Expandable Listview

final String GROUPTEXT = "GROUPTEXT";

final String CHILDTEXT1 = "CHILDTEXT1";
final String CHILDTEXT2 = "CHILDTEXT2";
SimpleExpandableListAdapter el_adapter;
ExpandableListView elv;
final ArrayList<HashMap<String, String>> groupData = new ArrayList<HashMap<String, String>>();
HashMap<String, String> currentGroupMap;
final ArrayList<ArrayList<HashMap<String, String>>> childrenData = new ArrayList<ArrayList<HashMap<String, String>>>();
ArrayList<HashMap<String, String>> currentChildList;
HashMap<String, String> currentChildMap;
for (int i = 0; i < 10; i++) {
currentGroupMap = new HashMap<String, String>();
currentGroupMap.put(GROUPTEXT,"Group" + (i+1));
groupData.add(currentGroupMap);
currentChildList = new ArrayList<HashMap<String, String>>();
for (int j = 0; j < 4; j++) {
currentChildMap = new HashMap<String, String>();
currentChildMap.put(CHILDTEXT1,"Group" + (i+1) + "_Child" + (j+1) + "_1");
currentChildMap.put(CHILDTEXT2,"Group" + (i+1) + "_Child" + (j+1) + "_2");
currentChildList.add(currentChildMap);
}
childrenData.add(currentChildList);
}
elv = new ExpandableListView(this); 
el_adapter = new SimpleExpandableListAdapter(getBaseContext(), groupData, android.R.layout.simple_expandable_list_item_1, new String[] { GROUPTEXT }, new int[] { android.R.id.text1 }, childrenData, android.R.layout.simple_expandable_list_item_2, new String[] { CHILDTEXT1, CHILDTEXT2 }, new int[] { android.R.id.text1, android.R.id.text2 }); 
elv.setAdapter(el_adapter);
elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
Toast.makeText(getApplicationContext(), "You Clicked : "+(groupData.get(groupPosition).get(GROUPTEXT)), Toast.LENGTH_SHORT).show();
return false;
}
});
elv.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
// Toast.makeText(getApplicationContext(), "Group Expanded", Toast.LENGTH_SHORT).show();
}
});
elv.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
//Toast.makeText(getApplicationContext(), "Group Collapsed", Toast.LENGTH_SHORT).show();
}
});

elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Toast.makeText(getApplicationContext(), "You Clicked : " + (childrenData.get(groupPosition).get(childPosition).get(CHILDTEXT1)), Toast.LENGTH_SHORT).show();
return false;
}
});
android.widget.LinearLayout.LayoutParams elv_params = new android.widget.LinearLayout.LayoutParams(-1, -2, 0);
linear1.addView(elv, elv_params);

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

TextInputLayout in Sketchware

How to find and​ highlight a word in a text field in Sketchware?

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation