最近,我试图利用和淡化可扩展的清单观点,因此,我 around绕了这一看法并 st了。
我几乎完全遵循了这些步骤,但我只建立了一个文件,以控制我自己的适应者的执行情况。 我所说的主要活动的基本方法是:
mEntries = findViewById(R.id.entries);
ExpandableListAdapter adapter = new MyExpandableListAdapter(this);
mEntries.setAdapter(adapter);
本条准则(摘自URL并修改):
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private String[] groups = {"Vehicle", "Baj"};
private String[][] children = {
{"Mol", "Mor"},
{"In", "Ruh"}
};
private Context cxt;
public MyExpandableListAdapter(Context cxt) {
this.cxt = cxt;
}
@Override
public Object getChild(int groupPos, int childPos) {
return children[groupPos][childPos];
}
@Override
public long getChildId(int groupPos, int childPos) {
return childPos;
}
@Override
public View getChildView(int groupPos, int childPos,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView tv = getGenericView();
tv.setText(getChild(groupPos, childPos).toString());
return tv;
}
@Override
public int getChildrenCount(int groupPos) {
return children[groupPos].length;
}
@Override
public Object getGroup(int groupPos) {
return groups[groupPos];
}
@Override
public int getGroupCount() {
return groups.length;
}
@Override
public long getGroupId(int groupPos) {
return groupPos;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView tv = new TextView(this.cxt);
tv.setLayoutParams(lp);
// Center the text vertically
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
tv.setPadding(36, 0, 0, 0);
return tv;
}
@Override
public View getGroupView(int groupPos, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView tv = getGenericView();
tv.setText(getGroup(groupPos).toString());
return null;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPos, int childPos) {
return true;
}
}
log:
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): java.lang.NullPointerException
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.AbsListView.obtainView(AbsListView.java:1276)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.ListView.makeAndAddView(ListView.java:1668)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.ListView.fillDown(ListView.java:637)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.ListView.fillFromTop(ListView.java:694)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.ListView.layoutChildren(ListView.java:1521)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.AbsListView.onLayout(AbsListView.java:1113)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.view.View.layout(View.java:6830)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:900)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.view.View.layout(View.java:6830)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.view.View.layout(View.java:6830)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.view.View.layout(View.java:6830)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
12-01 22:24:54.883: ERROR/AndroidRuntime(14424): at android.view.View.layout(View.java:6830)
snip...
任何人都想对此作出说明? =
EDIT: I ve already implemented the methods required in the Base class.
EDIT2: Code added