当前位置:网站首页>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"/>
边栏推荐
- Flash build API service
- Solid function learning
- [video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
- 99% of users often make mistakes in power Bi cloud reports
- 到底有多二(Lua)
- textSwitch文本切换器的功能和用法
- 【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
- 【网络攻防原理与技术】第5章:拒绝服务攻击
- LeetCode 535(C#)
- LeetCode 497(C#)
猜你喜欢
Biped robot controlled by Arduino
Mrs offline data analysis: process OBS data through Flink job
TabHOST 选项卡的功能和用法
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
99%的人都不知道|私有化部署还永久免费的即时通讯软件!
DatePickerDialog和trimepickerDialog
网络攻防复习篇
viewflipper的功能和用法
【TPM2.0原理及应用指南】 16、17、18章
状态模式 - Unity(有限状态机)
随机推荐
Repair method of firewall system crash and file loss, material cost 0 yuan
MySQL usage notes 1
[Fantan] how to design a test platform?
第3章业务功能开发(用户访问项目)
L1-027 出租(Lua)
Audio device strategy audio device output and input selection is based on 7.0 code
【信息安全法律法规】复习篇
Rpcms method of obtaining articles under the specified classification
Sator推出Web3游戏“Satorspace” ,并上线Huobi
LeetCode刷题day49
2021-06-28
《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
数值 - number(Lua)
DNS series (I): why does the updated DNS record not take effect?
How to implement safety practice in software development stage
datepicket和timepicket,日期、时间选择器的功能和用法
【网络攻防原理与技术】第3章:网络侦察技术
字符串 - string(Lua)
Functions and usage of viewswitch
Sator launched Web3 game "satorspace" and launched hoobi