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;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---