SearchView--搜索框案例
来源:互联网 发布:c语言base64编码 编辑:程序博客网 时间:2024/05/16 08:55
页面布局content_main.xml
<? xml version= "1.0" encoding= "utf-8" ?><LinearLayout xmlns: android ="http://schemas.android.com/apk/res/android" android :layout_width= "match_parent" android :layout_height= "match_parent" android :orientation= "vertical"> <!--定义一个SearchVieww--> <SearchView android :id= "@+id/searchView" android :layout_width= "match_parent" android :layout_height= "wrap_content" /> <ListView android :id= "@+id/listView" android :layout_width= "match_parent" android :layout_height= "0dp" android :layout_weight= "1"/></LinearLayout>
主程序SearchViewTest
package com.eson.searchview ;import android.os.Bundle ;import android.support.v7.app.AppCompatActivity ;import android.text.TextUtils ;import android.widget.ArrayAdapter ;import android.widget.ListView ;import android.widget.SearchView ;import android.widget.Toast ;public class SearchViewTest extends AppCompatActivity implements SearchView.OnQueryTextListener { private final String[] mString={ "android" ,"html" , "ios", "java" ,"javaScript" , "css", "node.js" }; private ListView listView ; private SearchView searchView ; @Override protected void onCreate (Bundle savedInstanceState) { super .onCreate(savedInstanceState) ; setContentView(R.layout. content_main ); listView = (ListView) findViewById(R.id. listView ); listView .setAdapter( new ArrayAdapter<String>( this, android.R.layout. simple_list_item_1, mString )); listView .setTextFilterEnabled( true) ; searchView = (SearchView) findViewById(R.id. searchView ); //设置该SearchView默认是否自动缩小为图标 searchView .setIconifiedByDefault( false) ; //为该SearchView组件设置事件监听器 searchView .setOnQueryTextListener( this ); //设置该SearchView内默认显示的提示文本 searchView .setQueryHint( "查找" ); } //用户输入字符激发该方法 @Override public boolean onQueryTextSubmit (String query) { //实际应用中应该执行该方法内执行实际查询 //此处仅使用Toast显示用户输入的查询内容 Toast. makeText( this, "您的选择是:" +query, Toast. LENGTH_SHORT).show() ; return false; } //单击搜索按钮时激发该方法 @Override public boolean onQueryTextChange (String newText) { if (TextUtils. isEmpty(newText)){ //清除ListView的过滤 listView .clearTextFilter() ; } else { //使用用户输入的内容对ListView的列表进行过滤 listView .setFilterText(newText) ; } return true; }}
1 0
- SearchView--搜索框案例
- SearchView搜索框
- 搜索框(SearchView)详解
- SearchView搜索框
- 自定义搜索框searchview
- 自定义搜索框(SearchView)
- 修改searchview搜索框光标
- 搜索框—— SearchView
- 搜索SearchView
- SearchView---搜索
- 自定义超简单SearchView搜索框
- 【转】自定义搜索框(SearchView)
- Android学习笔记(29):搜索框SearchView
- <SearchView > 搜索框的简单使用
- 安卓自定义搜索框(searchview)
- UI组件:搜索框(SearchView)
- 使用SearchView+RecyclerView做搜索框
- Searchview搜索框点击事件失效解决方案
- android中如何将下载的图片保存到手机SD(外部存储)卡中
- uva 10652(凸包)
- innobackupex恢复操作报错两例
- 移动端开发:使用jQuery Mobile还是Zepto
- OC字符串去除首字母,OC字符串去除-号
- SearchView--搜索框案例
- 第12周【项目 1-实现复数类中的运算符重载(1)】
- Selenium2+JUnit+FirefoxDriver操作页面中的选择按钮
- 解决WORD “未找到引用源”问题
- ecshop二次开发各种文档下载
- LaTeX新人教程,30分钟从完全陌生到基本入门
- 膨胀和腐蚀在MATLAB中
- Linux 安装软件备忘录
- ubuntu下Qt cannot find -lGL错误的解决方法