gpt4 book ai didi

android - 将静态数据添加到使用 ListAdapter 动态创建的 ListView

转载 作者:行者123 更新时间:2023-11-30 04:40:09 24 4
gpt4 key购买 nike

我想将 X 个静态行添加到 ListView,该 ListView 当前使用 ListAdapter/BaseAdapter 动态填充 ListView。有什么建议么?

提前致谢,科尔。

我的解决方案:根据@Femi 的建议,我最终使用了 MergeAdapter。这是我所做的一个 fragment :

    // create a new MergeAdapter
MergeAdapter aMergeAdapter = new MergeAdapter();

// add the dynamic content
SkipToListActivityValueAdapter skipToListActivityValueAdapter =
new SkipToListActivityValueAdapter(this, sections);
aMergeAdapter.addAdapter(skipToListActivityValueAdapter);

// add the static content
ArrayAdapter<String> aArrayAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ADDITIONAL_SKIP_TO_OPTIONS);
aMergeAdapter.addAdapter(aArrayAdapter);

// add the aMergeAdapter to the ListAdapter
setListAdapter(aMergeAdapter);

最佳答案

答案是@commonsware 的MergeAdapter。参见 https://github.com/commonsguy/cwac-merge有关详细信息,但非常方便的异构数据源代码。您可以按照您想要的任何顺序很好地拼接多个适配器和 View 。

关于android - 将静态数据添加到使用 ListAdapter 动态创建的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6133538/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com