i have developed one dynamic expandablelistview successfully...how is dynamically create expandablelictview within another expandalilistview. this is my code:
public class SingleMenuItemActivity extends ExpandableListActivity {
Button btninsert;
String selectedItem;
static final String KEY_NAME = "orderid";
static final String KEY_STATUS = "status";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.particular);
Button btninsert = (Button) findViewById(R.id.btn_insert);
btninsert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String s= getIntent().getStringExtra("orderid");
String s1= getIntent().getStringExtra("status");
Intent i = new Intent(getApplicationContext(), InsertionExample.class);
i.putExtra(KEY_NAME, s);
i.putExtra(KEY_STATUS, s1);
startActivity(i);
}
});
// Construct Expandable List
final String NAME1 = "payment_method1";
final String NAME = "payment_method";
final String TOTAL = "total";
final String TOTAL1 = "total1";
final String IMAGE = "image";
final String FNAME1 = "firstname1";
final String FNAME = "firstname";
final String LNAME1 = "lastname1";
final String LNAME = "lastname";
final String PHONE1 = "phone1";
final String PHONE = "phone";
final String EMAIL1 = "email1";
final String EMAIL = "email";
final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();
final HashMap<String, String> group1 = new HashMap<String, String>();
group1.put(NAME, "OrderInfo");
headerData.add( group1 );
final HashMap<String, String> group2 = new HashMap<String, String>();
group2.put(NAME, "CustomerInfo");
headerData.add( group2);
final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();
final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
childData.add(group1data);
final ArrayList<HashMap<String, String>> group2data = new ArrayList<HashMap<String,String>>();
final HashMap<String, String> group3 = new HashMap<String, String>();
group3.put(NAME, "PersonalInfo");
group2data.add( group3 );
final HashMap<String, String> group4 = new HashMap<String, String>();
group4.put(NAME, "ContactInfo");
group2data.add( group4 );
final ArrayList<HashMap<String, Object>> group3data = new ArrayList<HashMap<String, Object>>();
childData.add(group3data);
final ArrayList<HashMap<String, Object>> group4data = new ArrayList<HashMap<String, Object>>();
childData.add(group4data);
// Set up some sample data in both groups
final HashMap<String, Object> map = new HashMap<String,Object>();
String s= getIntent().getStringExtra("payment_method");
String s1= getIntent().getStringExtra("total");
map.put(NAME1, "Payment_method:");
map.put(NAME, s );
map.put(TOTAL1, "Total:");
map.put(TOTAL, s1);
group1data.add(map);
// map.put(IMAGE, getResources().getDrawable((i%3==0? R.drawable.color_green : R.drawable.color_red)));
// ( i%2==0 ? group1data : group2data ).add(map);
final HashMap<String, Object> map1 = new HashMap<String,Object>();
String s2= getIntent().getStringExtra("firstname");
String s3= getIntent().getStringExtra("lastname");
map1.put(FNAME, s2);
map1.put(FNAME1, "Firstname:");
map1.put(LNAME, s3);
map1.put(LNAME1, "Lastname:");
// map.put(IMAGE, getResources().getDrawable(R.drawable.color_yellow));
group3data.add(map1);
final HashMap<String, Object> map2 = new HashMap<String,Object>();
String s4= getIntent().getStringExtra("phone");
String s5= getIntent().getStringExtra("email");
map2.put(PHONE, s4);
map2.put(PHONE1, "Phone:");
map2.put(EMAIL, s5);
map2.put(EMAIL1, "Email:");
// map.put(IMAGE, getResources().getDrawable(R.drawable.color_yellow));
group4data.add(map2);
setListAdapter( new SimpleExpandableListAdapter(
this,
headerData,
R.layout.group_row,
new String[] { NAME }, // the names of the data
new int[] { R.id.order },
// the text field to populate with the field data
childData,
0,
null,
new int[] {}
) {
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
// Spinner spinner = (Spinner) findViewById(R.id.spnMusketeers);
// Populate your custom view here
((TextView)v.findViewById(R.id.payment_method1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME1) );
((TextView)v.findViewById(R.id.payment_method)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME) );
((TextView)v.findViewById(R.id.phone1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(PHONE1) );
((TextView)v.findViewById(R.id.phone)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(PHONE) );
((TextView)v.findViewById(R.id.email1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(EMAIL1) );
((TextView)v.findViewById(R.id.email)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(EMAIL) );
((TextView)v.findViewById(R.id.firstname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME) );
((TextView)v.findViewById(R.id.firstname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME1) );
((TextView)v.findViewById(R.id.total1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL1) );
((TextView)v.findViewById(R.id.total)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL) );
((TextView)v.findViewById(R.id.lastname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(LNAME) );
((TextView)v.findViewById(R.id.lastname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(LNAME1) );
return v;
}
@Override
public View newChildView(boolean isLastChild, ViewGroup parent) {
return layoutInflater.inflate(R.layout.expandable_list_item_with_image,null, false);
}
}
);
ExpandableListView list = (ExpandableListView) findViewById(android.R.id.list);
list.setOnChildClickListener(new OnChildClickListener(){
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
System.out.println("Group:"+groupPosition+", Child: "+childPosition);
return true;
}
});
}}
Here i wish to display the output is below format:
---->Orderinfo
* payment_method
* total
---->Customerinfo
---->Personalinfo
* firstname
* lastname
----->Contactinfo
* phone
* email
Here i can't develop this.
here how can i implement my code???
here i have created headerData(orderinfo,customerinfo) and group2data(personalinfo,contactinfo) for creating groups.Here i have used headerData only on below code.
setListAdapter( new SimpleExpandableListAdapter(
this,
headerData,
R.layout.group_row,
new String[] { NAME }, // the names of the data
new int[] { R.id.order },
// the text field to populate with the field data
childData,
so ly created orderinfo and customerinfo groups only.but i can't add group2data here.here i have add groupdata on this line means i got the following error:
- Breakpoint:SingleMenuItemActivity - Line breakpoint:SingleMenuItemActivity [line: 134] - onCreate(Bundle) - The constructor SimpleExpandableListAdapter(SingleMenuItemActivity, ArrayList>, ArrayList>, int, String[], int[], ArrayList>>, int, null, int[]) is undefined
How can i resolve my error.please help me.