以下代码当前正在 Activity 中工作。但我想将它用于片段,当我尝试时它无法识别我的可扩展列表。如果有人可以帮助我,这将是一个很大的帮助。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_expandable_list);
createGroupList();
createCollection();
expListView = (ExpandableListView) findViewById(R.id.my_exp_list);
final ExpandableListAdapter expListAdapter = new ExpandableListAdapter(
this, groupList, laptopCollection);
expListView.setAdapter(expListAdapter);
setGroupIndicatorToRight();
expListView.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
final String selected = (String) expListAdapter.getChild(
groupPosition, childPosition);
Toast.makeText(getBaseContext(), selected, Toast.LENGTH_LONG)
.show();
return true;
}
});
}
在我的片段 oncreateView 中,
View v = inflater.inflate(R.layout.activity_expandable_list, container, false); createGroupList();
createCollection();
expListView = (ExpandableListView) inflater.inflate(R.id.my_exp_list, container, false);