【问题标题】:Expandable Listview with Listview and Custom Adapters带有 Listview 和自定义适配器的可扩展 Listview
【发布时间】:2016-02-21 20:54:48
【问题描述】:

PRJ 包含: 具有 ExpandableListView 的 Frag_Settings,使用自定义适配器,我将其命名为 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 项目... :(

-总而言之,有什么方法可以更简单地实现这一点?

-我遵循的方法对吗?

【问题讨论】:

    标签: android listview fragment custom-adapter expandable


    【解决方案1】:

    没办法^这种方式问题太多了....

    我发现了一个手动解决方案,正如我所说,视图是静态的 https://tsicilian.wordpress.com/2013/09/02/android-tips-expandablecollapsible-views/

    【讨论】:

      猜你喜欢
      • 2013-05-21
      • 1970-01-01
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多