【问题标题】:ListView only showing first result - only in mobile device : MasterDetail ViewListView 仅显示第一个结果 - 仅在移动设备中:MasterDetail View
【发布时间】:2017-04-17 07:46:21
【问题描述】:

我的Master/Detail 基于模板的应用程序的详细视图中有这个问题。 我在详细视图中填充可扩展列表。它在平板电脑视图中运行良好。但在移动设备中,它只向我显示第一个结果。我什至尝试删除CollapsingToolbarLayout 以确保列表视图不会被任何其他滚动选项阻塞。但我找不到问题。

设置适配器

ArrayList<ClientList> clientLists = ClientList.getClientList(getActivity(), clientResult);
Log.e("Client","--"+clientLists.size()); //Im getting the list size as normal 
clientExpandableAdapter = new ClientExpandableAdapter(getActivity(), clientLists);
expandableListView.setAdapter(clientExpandableAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
        return false;
    }
});

详细视图布局

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xxx.xxx.ItemDetailFragment"
    android:textIsSelectable="true"
    android:paddingBottom="16dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:background="@drawable/bottom_border"
            android:id="@+id/mainViewHeader">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:id="@+id/titleHeader"
            android:text="Clients" />
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:id="@+id/titleCountHeader"
            android:text="Clients"
            />
        </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/mainViewHeader"
        android:id="@+id/backgroundView"
        android:background="@color/colorWhite">

            <ExpandableListView
                android:id="@+id/mainExpandableDatalist"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </ExpandableListView>

        </RelativeLayout>

</RelativeLayout>

【问题讨论】:

    标签: android listview expandablelistview master-detail


    【解决方案1】:

    在我看来,在这类问题中可能会出现很多错误。

    1. 您可能已将 ScrollView 作为 listview 的父级,这根本不是必需的。
    2. ListView 或自定义 ListView 布局的根元素的高度可以是match_parent | fill_parent,在整个屏幕中显示单个项目。

    如果你也显示布局文件会更好。

    【讨论】:

    • 我尝试按照您的建议更改布局高度。仍然没有成功。顺便说一句,我已经用布局文件更新了问题
    • 我发现了问题。问题出在 ExpandableListView 高度。一旦我给了自定义高度。数据开始显现。但令人困惑的是为什么它只出现在移动设备中
    • 您用代码修改的问题没问题,但同样取决于您为自定义列表视图创建的布局。如果 ExpandableCustomListView 布局的父级高度为 match_parent 则它也覆盖全屏的单个项目。
    猜你喜欢
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2021-05-12
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多