我在 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 .
这需要适配器
和 View
并将它们显示为一个合并的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/