java - Android搜索过滤器在没有结果时显示文本视图
问题描述
我有一个列表视图和搜索视图。当搜索过滤器给出的结果与列表视图中的任何项目都不匹配时,我需要将 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>
解决方案
您可以做的是,在您的列表视图适配器上,当您使用的数组为空时,在您的 getItemCount 上,您返回 1,当您返回视图时,如果数组为空,您将返回一个带有“Nothing”的视图当下”。
推荐阅读
- python - 在 for 循环中通过数据框附加字符串
- c# - 不使用 Collection 构建队列
- reactjs - 延迟更新数组 React 的 setState
- mysql - 在mysql中以相反的顺序将表加入到自身中
- android - Android Room:查询不返回所有包含连接的行
- sql - 寻求改进的 SQL 查询
- proxy - Squid 代理无法访问受 Cloudflare 保护的网站
- c++ - 需要一个参考折叠规则的例子 T&&&& -> T&& on VS2017
- javascript - 将带有许多 && 的长 if 语句转换为带有 javascript 的 for 循环
- python - 通过 Python 将 CSV 文件中的数据批量/插入到 CosmosDB