[英]How to add a functional search bar to a navigation drawer?
我正在开发一种墙纸应用程序,该应用程序可从Picasa加载其图像。我有一个导航抽屉,可从Picasa相册名称中检索其商品名称(我正在使用本教程的源代码链接 ),所以我想添加一个用于过滤的搜索栏导航抽屉中的项目,关于如何完成此操作的任何想法?
It might be a little late. 可能会晚一点。 But may help others. 但可能会帮助别人。
Add an EditText to navigation Drawer.(activity_main.xml) 将EditText添加到导航抽屉。(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>
add a TextWatcher to editText. 将TextWatcher添加到editText。 (Add the following lines to onCreate
) ( onCreate
添加到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
. 您可以将导航抽屉ArrayAdapter
包含ArrayAdapter
的Fragment
,该Fragment
实现Filterable
。 This adapter would contain list of your Picasa album names. 该适配器将包含您的Picasa相册名称列表。
For the search box, a simple EditText
would do the job. 对于搜索框,可以使用简单的EditText
来完成。 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. 注册一个TextWatcher
,它将侦听文本更改事件,并在ArrayAdapter.getFilter()
返回的Filter
上触发Filter.filter()
,并将输入文本作为查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.