我创建了一个DrawerLayout
,并且它在ListView
之上有一个用于在ListView
上搜索的EditText
。我现在如何在DrawerLayout
上进行主动搜索?
这对我来说很好:
在xml中,在列表视图上方包含一个edittext:
<EditText
android:inputType="text"
android:id="@+id/searchTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
在java文件中:
mSearchText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
adapter.getFilter().filter(s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
这里mSearchText
是来自xml文件的searchTxt
,adapter
将是导航抽屉列表视图的适配器。
希望能有所帮助。