0

I create a DrawerLayout and it have a EditText above of ListView for search on ListView . How i can active search on DrawerLayout now ?

A.A
  • 1,138
  • 1
  • 16
  • 29

1 Answers1

1

This is working fine for me:

In xml, include an edittext just above the listview:

<EditText 
    android:inputType="text"
    android:id="@+id/searchTxt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#ffffff"
/>

In java file:

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

    }
});

Here mSearchText is the searchTxt from xml file and adapter will be the adapter of your navigation drawer listview.

Hope it helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124