ExpandableListAdapter problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ExpandableListAdapter problem

Postby The_One_Neo » Tue Feb 10, 2009 11:01 am

In my code , i used the ExpandableListAdapter.

In the getChildView(), i want my child item have two textview in it.
So i create a RelativeLayout viewGroup.
i debug it but it crash.

problem if return the RelativeLayout be crash.
if i return a TextView no problem,
may be can't return ViewGroup ???
i don't know ,please help me ,thanks

Follow code :

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].

public Object getChild(int groupPosition, int childPosition) {
return app.childData.get(groupPosition).get(childPosition);
//return children[groupPosition][childPosition];
}

public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}

public int getChildrenCount(int groupPosition) {
return app.childData.get(groupPosition).size();
}

public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);

TextView textView = new TextView(CarteList.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;
}

public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
RelativeLayout layout = new RelativeLayout(CarteList.this);
layout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
64));

RelativeLayout.LayoutParams paramsPicture = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);


TextView textView1 = new TextView(CarteList.this);
textView1.setLayoutParams(paramsPicture);
textView1.setText(app.groupData.get(groupPosition).toString());
layout.addView(textView1);

TextView textView2 = new TextView(CarteList.this);
textView2.setLayoutParams(paramsPicture);
textView2.setText(app.groupData.get(groupPosition).toString());
layout.addView(textView2);

return layout;
}

public Object getGroup(int groupPosition) {
return app.childData.get(groupPosition);
}

public int getGroupCount() {
return app.childData.size();
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(app.groupData.get(groupPosition).toString());
return textView;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}

public boolean hasStableIds() {
return true;
}
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 10 guests