当前位置:网站首页>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"/>
边栏推荐
猜你喜欢
VSCode关于C语言的3个配置文件
Functions and usage of viewswitch
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
【TPM2.0原理及应用指南】 12、13、14章
企业即时通讯软件是什么?它有哪些优势呢?
让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
第3章业务功能开发(安全退出)
Matplotlib绘制三维图形
How to choose the appropriate automated testing tools?
TabHOST 选项卡的功能和用法
随机推荐
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
第3章业务功能开发(安全退出)
Functions and usage of imageswitch
imageswitcher的功能和用法
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
The top of slashdata developer tool is up to you!!!
大笨钟(Lua)
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
L1-028 判断素数(Lua)
rpcms获取指定分类下的文章的方法
ViewSwitcher的功能和用法
DevOps 的运营和商业利益指南
国内首创!Todesk将RTC技术融入远程桌面,画质更清晰操作更流畅
Sator推出Web3遊戲“Satorspace” ,並上線Huobi
麒麟信安云平台全新升级!
Mrs offline data analysis: process OBS data through Flink job
【TPM2.0原理及应用指南】 9、10、11章
Flash build API service
如何在软件研发阶段落地安全实践
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR