简体   繁体   中英

How to add a functional search bar to a navigation drawer?

我正在开发一种墙纸应用程序,该应用程序可从Picasa加载其图像。我有一个导航抽屉,可从Picasa相册名称中检索其商品名称(我正在使用本教程的源代码链接 ),所以我想添加一个用于过滤的搜索栏导航抽屉中的项目,关于如何完成此操作的任何想法?

It might be a little late. But may help others.

  1. Add an EditText to navigation Drawer.(activity_main.xml)

     <EditText android:id="@+id/inputSearch" android:layout_width="match_parent" android:layout_height="40dp" android:layout_margin="10dp" android:hint="search" android:padding="10dp" android:layout_marginTop="25dp" android:inputType="text" > </EditText> 
  2. add a TextWatcher to editText. (Add the following lines to onCreate )

      final EditText inputSearch = (EditText) findViewById(R.id.inputSearch); inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub //You should use the adapter in NavigationDrawerFragment NavigationDrawerFragment.adapter.getFilter().filter(cs); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } }); 

Hope this helps.

You can make your navigation drawer a Fragment that contains an ArrayAdapter , which implements Filterable . This adapter would contain list of your Picasa album names.

For the search box, a simple EditText would do the job. Register a TextWatcher that would listen to text change events and trigger Filter.filter() on a Filter returned from your ArrayAdapter.getFilter() with input text as query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM