gpt4 book ai didi

android - 在 ListView 内的 ListView 中重复使用(或适配器内的适配器)

转载 作者:搜寻专家 更新时间:2023-11-01 08:46:48 25 4
gpt4 key购买 nike

我在 stackover 中听说可以将 listview 放在 listview 中或将 listview 放在 scrollview 中,因此可以将适配器放在适配器中。内部可滚动元素将失去滚动属性。但是重用呢?如果它是一个 ListView 中的一个 ListView ,并且都有自己的列表适配器或派生基础……他们都能够重用自己的项目吗?还是其中之一?

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:text="Artists"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:text="Albums"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:text="Tracks"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:text="Playlists"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ListView>
</FrameLayout>

最佳答案

我想您需要的是由 commonsguy 的 Mergeadapter 实现的:https://github.com/commonsguy/cwac-merge .

这需要 AdaptersViews 并将它们显示为一个合并的 Listview

MergeAdapter accepts a mix of Adapters and Views and presents them as one contiguous whole to whatever ListView it is poured into. This is good for cases where you have multiple data sources, or if you have a handful of ordinary Views to mix in with lists of data, or the like.

Simply create a MergeAdapter and call addAdapter(), addView(), or addViews() (latter accepting a List), then attach your adapter to the ListView.

There is also MergeSpinnerAdapter for use with Spinner widgets.

关于android - 在 ListView 内的 ListView 中重复使用(或适配器内的适配器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27485270/

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