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

边栏推荐
- First in China! Todesk integrates RTC technology into remote desktop, with clearer image quality and smoother operation
- How to implement safety practice in software development stage
- Flask搭建api服务-SQL配置文件
- 【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
- 【TPM2.0原理及应用指南】 5、7、8章
- Linux 安装mysql8.X超详细图文教程
- [fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
- [Huang ah code] Why do I suggest you choose go instead of PHP?
- 请将磁盘插入“U盘(H)“的情况&无法访问 磁盘结构损坏且无法读取
- 2021-06-28
猜你喜欢
随机推荐
Function and usage of textswitch text switcher
LeetCode刷题day49
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
第2章搭建CRM项目开发环境(搭建开发环境)
mysql使用笔记一
专精特新软件开发类企业实力指数发布,麒麟信安荣誉登榜
From Devops to mlops: how do it tools evolve to AI tools?
自定义View必备知识,Android研发岗必问30+道高级面试题
使用Stace排除故障的5种简单方法
Several best practices for managing VDI
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
【TPM2.0原理及应用指南】 1-3章
DevOps 的运营和商业利益指南
LeetCode 890(C#)
【网络攻防原理与技术】第4章:网络扫描技术
DNS 系列(一):为什么更新了 DNS 记录不生效?
第3章业务功能开发(安全退出)
跟奥巴马一起画方块(Lua)
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination









