可扩展组是5并且是静态的(也称为预定义的)。每个组都适应不同的视图。其中一个视图有listview,它还实现了一个自定义适配器(从dbase获取记录)......
所以让我们看看,我目前所写的内容,可扩展 Frag_Settings_Adapter :
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater inflater = null;
switch (groupPosition) {
case 0:
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.frag_settings_row_detail_01_cities, null);
break;
case 1:
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.frag_settings_row_detail_02_categories, null);
//raise event to parent
if (listener_02_categories != null)
listener_02_categories.fill_with_data(convertView);
break;
}
return convertView;
}
当群组为2时,给视图充气+使用视图将事件提升为片段 (这样好吗?)
然后在片段 onActivityCreated ,当设置 expandable_listview 时:
listAdapter = new Frag_Settings_Adapter(getActivity(), listDataHeader, listDataChild);
listAdapter.setListener(new Fill_02_Categories_Listener() {
@Override
public void fill_with_data(View convertView) {
////////////////////////////////////////////////
//////////////listview 02 - categories
lstv = (ListView) convertView.findViewById(R.id.frag_settings_row_detail_categories_lstv);
Frag_Settings_Categories_LIST = new ArrayList<Frag_Settings_Categories>();
lstv.setOnItemClickListener(this);
lstv_adapter = new Frag_Settings_Categories_Adapter(getActivity(), Frag_Settings_Categories_LIST);
lstv.setAdapter(lstv_adapter);
CategoriesDatasource categories_datasource = new CategoriesDatasource(getActivity());
for (Categories d : categories_datasource.getAllCategoriess()) {
Frag_Settings_Categories_LIST.add(new Frag_Settings_Categories(d.getid(),d.getcategory_name(),false));
}
lstv.setAdapter(lstv_adapter);
}
});
// setting list adapter
expListView.setAdapter(listAdapter);
- 这一个工作,但我以某种方式增加了可扩展组2的高度,因为现在我只能看到1listview项目...... :(
- 除此之外,有没有办法以更简单的方式实现这一目标?
- 我遵循的方法是正确的吗?
答案 0 :(得分:0)
没办法^那样的问题太多了......
我发现了一个手动解决方案,就像我说的那样,视图是静态的https://tsicilian.wordpress.com/2013/09/02/android-tips-expandablecollapsible-views /