当前位置:网站首页>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"/>

边栏推荐
- 【TPM2.0原理及应用指南】 9、10、11章
- 请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
- imageswitcher的功能和用法
- 百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
- 使用popupwindow創建对话框风格的窗口
- 第3章业务功能开发(安全退出)
- 鲲鹏开发者峰会2022 | 麒麟信安携手鲲鹏共筑计算产业新生态
- 【可信计算】第十三次课:TPM扩展授权与密钥管理
- The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
- DatePickerDialog和trimepickerDialog
猜你喜欢

麒麟信安携异构融合云金融信创解决方案亮相第十五届湖南地区金融科技交流会

TabHOST 选项卡的功能和用法

Nerf: the ultimate replacement for deepfake?

【TPM2.0原理及应用指南】 16、17、18章

Function and usage of numberpick

Matplotlib绘制三维图形

ViewSwitcher的功能和用法
![[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

第2章搭建CRM项目开发环境(数据库设计)

Matplotlib绘图界面设置
随机推荐
【TPM2.0原理及应用指南】 16、17、18章
百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
【网络攻防原理与技术】第5章:拒绝服务攻击
从DevOps到MLOps:IT工具怎样向AI工具进化?
【可信计算】第十三次课:TPM扩展授权与密钥管理
简单的loading动画
第二十四届中国科协湖南组委会调研课题组一行莅临麒麟信安调研考察
企业即时通讯软件是什么?它有哪些优势呢?
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism
【TPM2.0原理及应用指南】 12、13、14章
第3章业务功能开发(用户登录)
The computer cannot add a domain, and the Ping domain name is displayed as the public IP. What is the problem? How to solve it?
【网络攻防原理与技术】第3章:网络侦察技术
Notes on installing MySQL in centos7
Sator launched Web3 game "satorspace" and launched hoobi
【网络攻防原理与技术】第4章:网络扫描技术
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
Sator推出Web3游戏“Satorspace” ,并上线Huobi
请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
【饭谈】那些看似为公司着想,实际却很自私的故事 (一:造轮子)