就好像他们根本不存在一样。它可以编译,但在每个组中都没有可见或可选择的内容。这是一个屏幕截图:
这是我的活动课。孩子们的膨胀 xml 几乎没有。
package com.anthonyce.mcathomie;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class PlayoptionsActivity extends Activity {
ExpandableListView Mtopics;
ExpandableAdapter MtopicsAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_playoptions);
//set up adapter
MtopicsAdapter = new ExpandableAdapter();
Mtopics = (ExpandableListView) findViewById(R.id.mtopicsListView);
Mtopics.setAdapter(MtopicsAdapter);
//Mtopics.setGroupIndicator(null);
}
public class ExpandableAdapter extends BaseExpandableListAdapter {
private String[] groups = { "People Names", "Dog Names", "Cat Names",
"Fish Names" };
private String[][] children = { { "Arnold" }, { "Ace" }, { "Fluffy" },
{ "Goldy" } };
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final class ExpandChildRow extends LinearLayout {
public ExpandChildRow(Context context) {
super(context);
LayoutInflater childInflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout childView = (LinearLayout) childInflate.inflate(R.layout.mtopics_childrow, this, true);
TextView childtxt = (TextView)childView.findViewById(R.id.mtopicchildtext);
childtxt.setText(getChild(groupPosition, childPosition).toString());
}
}
ExpandChildRow ChildRow = new ExpandChildRow(getBaseContext());
return ChildRow;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(final int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final class ExpandGroupRow extends LinearLayout {
public ExpandGroupRow(Context context) {
super(context);
LayoutInflater groupInflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout groupView = (LinearLayout) groupInflate.inflate(R.layout.mtopics_grouprow, this, true);
TextView grouptxt = (TextView)groupView.findViewById(R.id.mtopicgrouptext);
grouptxt.setText(getGroup(groupPosition).toString());
}
}
ExpandGroupRow GroupRow = new ExpandGroupRow(getBaseContext());
return GroupRow;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
}