i am trying expandablelistview ,as given in api demo expandable list view example 1, use of string array , here i am facing the problem of converting the array list to string array, because all my values are saved in arraylist, the values are added into array list in asynctask, and the value of array list are retrieving in my adapter class which extends BaseExpandableListAdapter.
here is my code
1) array list decleration,
public final ArrayList<ListItemReminderSummary> listItemList = new ArrayList<ListItemReminderSummary>();
public final ArrayList<ListItemReminderSummaryList> listItemListSummary = new ArrayList<ListItemReminderSummaryList>();
2)adding values to array list in doinbackground()
ListItemReminderSummary listItem = new ListItemReminderSummary();
listItem.Car_Id = Vehicle_Id;
listItem.Car_Type = Car_Type;
listItemList.add(listItem);
ListItemReminderSummaryList SummaryList = new ListItemReminderSummaryList();
SummaryList.SummaryReminder_Id = Reminder_Id;
SummaryList.SummaryReminder_Type = Reminder_Type;
listItemListSummary.add(SummaryList);
@Override
protected void onPostExecute(String result)
{
mAdapter = new SlowAdapter(this);
ExpandableListView.setAdapter(mAdapter);
dialog.dismiss();
}
here is my adapter class
public class SlowAdapter extends BaseExpandableListAdapter {
private LayoutInflater mInflater;
private LoadData mContext;
private String[] groups=(String[]) listItemList.toArray(new String[listItemList.size()]);
private String[][] children = (String[][]) listItemListSummary.toArray(new String[listItemListSummary.size()][]);
public SlowAdapter(LoadData loadData) {
mContext = loadData;
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return children[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(ReminderSummary.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return children[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return groups[groupPosition];
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return groups.length;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
logcat
java.lang.ArrayStoreException: source[0] of type com.example.expandablelist.ListItemReminderSummary cannot be stored in destination array of type java.lang.String[]
so how to convert mt arraylist to string array, or i have to change my code to work with expandable listview,
this arraylist work for me to display values in a listview i want to make this arraylist work of expandable listview as well,
so please help me ,to get this done thank you...