首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在android.support.v4.widget.SwipeRefreshLayout中设置空视图

问如何在android.support.v4.widget.SwipeRefreshLayout中设置空视图
EN

Stack Overflow用户
提问于 2015-09-08 03:37:41
回答 1查看 825关注 0票数 0

我在这里看到了许多教程和其他内容,用于在列表为空时设置空视图。我有一个可以滑动刷新的列表。现在,我想在列表视图为空时在文本视图中显示一条文本消息。我逐渐知道,像这样设置是很简单的

代码语言:javascript
复制
myListview.setEmptyView(mEmptyViewContainer);

但是当列表视图中的数据为空时,它不会设置文本视图。下面是在阅读了一个问题后对我的xml的修改,他通过将文本视图包装在单独的swipeRefreshLayout中解决了这个问题。如下所示,这就是我的xml

代码语言:javascript
复制
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#dadada"

    >
        <RelativeLayout
    android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
       >

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <com.baoyz.swipemenulistview.SwipeMenuListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />




</android.support.v4.widget.SwipeRefreshLayout>
        </RelativeLayout>
    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeRefreshLayout_emptyView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sdasdadadfdasf"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:gravity="center"
        /></ScrollView>
    </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>

所以现在我不明白为什么它不显示我的空视图?会有什么问题呢?或者请告诉我有没有其他的方法?代码片段将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2015-09-08 11:21:26

你可以这样做:

在您的xml中:

代码语言:javascript
复制
<RelativeLayout>
    <SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout">
    </SwipeRefreshLayout>
    <TextView
        android:id="@+id/layout_empty"/>
</RelativeLayout>

java代码:

代码语言:javascript
复制
swipeView = (SwipeRefreshLayout) getActivity().findViewById(R.id.swipe_refresh_layout);
layoutEmpty = getActivity().findViewById(R.id.layout_empty);

当列表视图为空时:

代码语言:javascript
复制
layoutEmpty.setVisibility(View.VISIBLE);

当列表视图不为空时:

代码语言:javascript
复制
layoutEmpty.setVisibility(View.INVISIBLE);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32445074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档