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

标签 android listview xamarin scrollview baseadapter

我在 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/

相关文章:

java - 有没有更好的方法来了解 Activity 的生命周期状态,例如 isOnStop、isOnPause 等 API?

android - SMS 的垃圾邮件防护算法

php - 从 php 检索 JSON 时出错 - Android

java - 如何在我的 Android 应用程序中使用 onItemClick?

asp.net - 回发时 ListView 的 LayoutTemplate 中的数据绑定(bind)表达式

java - Activity 生命周期中的 onResume() 和 onPostResume() 有什么区别?

c# - ListView 标题复选框

c# - Nuget 无法安装 Xamarin.Android.Support.Animated.Vector.Drawable 27.0.2

c# - 在 Xamarin 中连接到 Azure 存储表

c# - NSAttributedString 不适用于 UITextField ios xamarin