PRJ 包含:Frag_Settings具有ExpandableListView,使用自定义adpater,我将其命名为listAdapter Frag_Settings_Adapter。
可扩展组为 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 时,将视图膨胀 + 引发事件以随视图碎片化! (这样好吗?
然后在片段中,当设置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 项目... :(
-总的来说,有没有办法以更简单的方式实现这一目标?
-我遵循的方法正确吗?
没办法^ 这种方式有太多问题....
我发现了一个手动解决方案,曾经我说过视图是静态的 https://tsicilian.wordpress.com/2013/09/02/android-tips-expandablecollapsible-views/