【问题标题】:How can I apply simpleExpandableListAdapter or similar thing to ListView in ListFragment如何将 simpleExpandableListAdapter 或类似的东西应用于 ListFragment 中的 ListView
【发布时间】:2011-08-16 06:36:23
【问题描述】:

我正在使用 ListFragment 并想制作一个困难的列表,其中包含子列表并且不知道我该怎么做(( 一些代码:

public class CarsOfBrandFragment extends ListFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        String[] s = {"colorName"};
        int[] k = {R.id.groupname};
        String[] s1 = new String[]{"shadeName", "rgb"};
        int[] k1 = new int[]{R.id.childname, R.id.rgb};
        SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(getActivity(), createGroupList(),
            R.layout.grouprow, s, k, createChildList(), R.layout.childrow, s1, k1);
        setListAdapter(expListAdapter);
    }

android.support.v4.app.ListFragment中的setListAdapter(android.widget.ListAdapter)不能应用到(android.widget.SimpleExpandableListAdapter)

【问题讨论】:

标签: android expandablelistview android-fragments


【解决方案1】:

你不能在 ListView 本身上设置它吗?

ListView lv = (ListView) findViewById(R.id.your_list);
lv.setAdapter(expListAdapter);

【讨论】:

  • 不,编译错误。显然这个适配器与 ListView 不兼容。也许还有其他方法?
  • 我在上面写道:android.support.v4.app.ListFragment 中的 setListAdapter(android.widget.ListAdapter) 不能应用于 (android.widget.SimpleExpandableListAdapter)
【解决方案2】:

好的,我通过明确指出 ExapndableListView 来决定这一点 - 是的,我在 Expandable 上更改了通常的 ListView,并使用 SimpleCursorTreeAdapter 而不是 SimpleExpandableListAdapter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 2019-09-09
    相关资源
    最近更新 更多