主要活动:
public class ListActivityEx extends Activity {
/** Called when the activity is first created. */
LayoutInflater inflate;
ExpandableListAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new MyCustomExpand(this);
ExpandableListView expand = (ExpandableListView) findViewById(R.id.expandableListView_profile);
expand.setAdapter(adapter);
}
}
适配器类:
public class MyCustomExpand extends BaseExpandableListAdapter {
LayoutInflater infalInflater;
private String[] groups = { "Test1", "Test2", "Test3" };
private String[][] children = {
{ "neelinfo", "MobileApp", "HYD" },
{ "rajesh", "palepu", "narasimha" },
{ "Android", "iphone", "J2ME" } };
// Add these lines to your code
private Context context;
public MyCustomExpand(Context context) {
this.context = context;
}
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_row, null);
}
TextView textView = (TextView) convertView.findViewById(R.id.childname3);
textView.setText(getChild(groupPosition, childPosition).toString());
return convertView;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
switch (groupPosition) {
case 0:
holder = new ViewHolder();
infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_row, null,
false);
holder.textView = (TextView) convertView
.findViewById(R.id.childname);
Log.d("heading", getGroup(groupPosition).toString());
holder.textView.setText(getGroup(groupPosition).toString());
break;
case 1:
infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_row2, null,
false);
holder = new ViewHolder();
holder.textView = (TextView) convertView
.findViewById(R.id.childname11);
// holder.textView.setText(getGroup(groupPosition).toString());
Log.d("heading", getGroup(groupPosition).toString());
holder.textView.setText(getGroup(groupPosition).toString());
case 2:
infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_row2, null,
false);
holder = new ViewHolder();
holder.textView = (TextView) convertView
.findViewById(R.id.childname11);
// holder.textView.setText(getGroup(groupPosition).toString());
Log.d("heading", getGroup(groupPosition).toString());
holder.textView.setText(getGroup(groupPosition).toString());
}
}
return convertView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
static class ViewHolder {
TextView textView;
}
}
答案 0 :(得分:0)
那是因为break
中没有case 1:
。和'案例2'