请在下面检查我的代码:
public class Expandable extends ExpandableListActivity implements OnChildClickListener {
ExpandableListView exp;
String[] parentList = {
"Timeless", "The Gap", "Series Break", "Will You", "Casting Call", "Beyond Normal"
};
String[][] childList = {
{
"God In The Past", "God In The Present", "God In The Future"
},
{
"Compassionate God", "Compassionate People"
},
{
"Living The Life In The Kingdom", "Characteristics Of Early Church"
},
{
"Be My Friend", "Be My Valentine", "Marry Me"
},
{
"Casting Call"
},
{
"Divine Courage", "Divine Guidance", "Divine Intervention"
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
exp = (ExpandableListView) findViewById (R.id.expandableListView1);
exp.setAdapter(new MyAdapter(this));
exp.setOnChildClickListener(this);
}
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
if(childList[childPosition].equals("God In The Past")){
Intent timeless = new Intent(this, MainActivity.class);
startActivity(timeless);
}
return true;
}
public class MyAdapter extends BaseExpandableListAdapter {
private Context context;
public MyAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
@Override
public Object getChild(int arg0, int arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getChildId(int arg0, int arg1) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView tv = new TextView(context);
tv.setText(childList[groupPosition][childPosition]);
tv.setPadding(50, 10, 10, 10);
return tv;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return childList[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return parentList.length;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView tv = new TextView(context);
tv.setText(parentList[groupPosition]);
tv.setPadding(30, 10, 10, 10);
return tv;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
// TODO Auto-generated method stub
return true;
}
}
}
但在一线
if(childList[childPosition].equals("God In The Past")){
String TAG = null;
Log.e(TAG, "God in the past");
Intent timeless = new Intent(this, MainActivity.class);
startActivity(timeless);
}
它似乎没有得到选定的子视图?我在这里缺少什么?
任何帮助表示赞赏。谢谢。