简单的搜索控件 小demo

时间:2018-07-29 10:28:35
【文件属性】:

文件名称:简单的搜索控件 小demo

文件大小:1.37MB

文件格式:RAR

更新时间:2018-07-29 10:28:35

tag

适合新手使用 代码片段: public class MainActivity extends Activity implements OnQueryTextListener { private SearchView search; private ListView list; private static final String[] strings = {"aaaa", "bbbb", "cccc"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list = (ListView)findViewById(R.id.listView); list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, strings)); list.setTextFilterEnabled(true); search = (SearchView)findViewById(R.id.searchView); search.setIconifiedByDefault(false); search.setQueryHint("Search"); search.setOnQueryTextListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onQueryTextSubmit(String query) { Toast.makeText(this, query, Toast.LENGTH_SHORT).show(); return false; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { list.clearTextFilter(); } else { list.setFilterText(newText); } return true; } }


【文件预览】:
SearchView-master
----SearchView-master()
--------.project(813B)
--------project.properties(563B)
--------src()
--------AndroidManifest.xml(861B)
--------res()
--------.settings()
--------LICENSE(11KB)
--------README.md(47B)
--------gen()
--------libs()
--------.classpath(466B)
--------.gitignore(271B)
--------proguard-project.txt(781B)
--------ic_launcher-web.png(50KB)
--------bin()

网友评论