抽屉列表上的主动搜索方式



我创建了一个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文件的searchTxtadapter将是导航抽屉列表视图的适配器。

希望能有所帮助。

最新更新