【发布时间】:2018-06-13 13:07:14
【问题描述】:
我有一个列表视图和搜索视图。当搜索过滤器给出的结果与任何项目都不匹配时 在列表视图中,我需要将 textview 显示为“Nothing present”。我该怎么做?
这是我的 xml -
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<SearchView
android:id="@+id/search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="60dp"/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</FrameLayout>
【问题讨论】:
-
你的过滤代码在哪里?
-
只需在 SwipeRefreshLayout 之后添加一个 TextView 并默认使其不可见。如果没有结果,则使其可见并且列表视图不可见。