[英]Expandable Listview with Listview and Custom Adapters
PRJ包含:Frag_Settings,它具有ExpandableListView,使用自定義適配器,我將其命名為Frag_Settings_Adapter listAdapter。
可擴展組是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;
}
當group為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項目... :(
-總而言之,有什么方法可以更輕松地實現這一目標?
-我遵循的方法正確嗎?
沒辦法^這樣有太多問題...
當我說視圖是靜態的https://tsicilian.wordpress.com/2013/09/02/android-tips-expandablecollapsible-views /
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.