支持Android V4 SwipeRefreshLayout空视图问题

问题描述:

SwipeRefresh没有设定一个空视图列表视图这是一个SwipeRefresh布局中唯一的孩子后工作。如何解决这个问题呢?

SwipeRefresh is not working after setting an empty view for listview which is the only child of a SwipeRefresh layout. How to solve this issue?

下面是解决方案: 你可以简单地使用这个视图层次:

Here is the solution: You can simply use this view hierarchy :

    <FrameLayout ...>

        <android.support.v4.widget.SwipeRefreshLayout ...>

            <ListView
                android:id="@android:id/list" ... />
        </android.support.v4.widget.SwipeRefreshLayout>

        <TextView
            android:id="@android:id/empty" ...
            android:text="@string/empty_list"/>
    </FrameLayout>

然后,在code,你只需要调用:

Then, in code, you just call:

_listView.setEmptyView(findViewById(android.R.id.empty));

就是这样。