当前位置:网站首页>Functions and usage of serachview
Functions and usage of serachview
2022-07-07 17:36:00 【XLMN】
serachview The function and usage of
searchview Is the search box component , Users can enter text in the text box , It also allows monitoring of user input through a listener , When user input completes submission search , You can also perform the actual search through the listener
public class MainActivity extends Activity {
private SearchView sv;
private ListView lv;
// Autocomplete list
private final String[] str = new String[]{
“mia”, “love mia”, “miss mia”, “010802”
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchview);
lv = findViewById(R.id.lv);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str));
// Set up listview Enable filtering
lv.setTextFilterEnabled(true);
sv = findViewById(R.id.searchview);
// Set up searchview Whether to automatically reduce to icon by default
sv.setIconifiedByDefault(false);
// Set up serarchview Show search button
sv.setSubmitButtonEnabled(true);
// Set up searchview The default prompt text displayed in
sv.setQueryHint(" lookup ");
// by searchview Add listener
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
// This method is triggered when the user searches the button
@Override
public boolean onQueryTextSubmit(String query) {
// In practice, the actual query should be executed in this method
// Only... Is used here toast Display the query content entered by the user
Toast.makeText(MainActivity.this, " Your choice is " + query, Toast.LENGTH_LONG);
return true;
}
// This method fires when the user enters a character
@Override
public boolean onQueryTextChange(String newText) {
// If nexttext Not in length 0 String
if (TextUtils.isEmpty(newText)) {
// clear listview Filter
lv.clearTextFilter();
} else {
// Let the user input content pair listview The list of items to filter
lv.setFilterText(newText);
}
return true;
}
});
}
}
<?xml version="1.0" encoding="utf-8"?><!-- Define a searchview-->
<SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/searchview"
/>
<!-- by searchview Define autocomplete listview-->
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/lv"/>

边栏推荐
- 赋能智慧电力建设 | 麒麟信安高可用集群管理系统,保障用户关键业务连续性
- LeetCode 515(C#)
- Devops' operational and commercial benefits Guide
- From Devops to mlops: how do it tools evolve to AI tools?
- 在窗口上面显示进度条
- L1-027 出租(Lua)
- The mail server is listed in the blacklist. How to unblock it quickly?
- 浅谈 Apache Doris FE 处理查询 SQL 源码解析
- Repair method of firewall system crash and file loss, material cost 0 yuan
- 【网络攻防原理与技术】第7章:口令攻击技术 第8章:网络监听技术
猜你喜欢

Numberpick的功能和用法

redis主从、哨兵主备切换搭建一步一步图解实现

Sator launched Web3 game "satorspace" and launched hoobi

自定义View必备知识,Android研发岗必问30+道高级面试题

User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions

百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示

【TPM2.0原理及应用指南】 12、13、14章

【TPM2.0原理及应用指南】 9、10、11章
![[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial](/img/14/4e7ebfb1ed5b99f8377af9d17d2177.jpg)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial

【可信计算】第十二次课:TPM授权与会话
随机推荐
【信息安全法律法規】複習篇
DevOps 的运营和商业利益指南
Devops' operational and commercial benefits Guide
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
第1章CRM核心业务介绍
百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
How to implement safety practice in software development stage
Functions and usage of ratingbar
SlashData开发者工具榜首等你而定!!!
Smart logistics platform: make overseas warehouses smarter
简单的loading动画
【黄啊码】为什么我建议您选择go,而不选择php?
Solidity函数学习
2021-06-28
【分布式理论】(二)分布式存储
智慧物流平台:让海外仓更聪明
What is cloud computing?
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
命令模式 - Unity