• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps "onkey" search interface

MrLondon

Lurker
Hey i want to create an edittext and a listview. this listview contains some strings, i want to be able to search these strings the same time the user enters the input

like

Cat
Dog
Monkey <-
Squirrel

when the user then types M it picks out the above and only shows that one like

--- Shows ---

Monkey

but i dont wanna search the start letter only i wanna keep searching as he types, like if he types as below it shows nothing.

--- Typed ---

Mok

--- Shows ---

nothing


i was thinking about doing in it a onTextChanged but i dont know how to make the search function, do you know if there is any tutorials out there? or do anyone know how i need to do
 
this is not search , what you are looking for is filtering
I did the same mistake before too, I'll try to give you some stuff from my code
at first , you'll need to have an ArrayAdapter for your list , let's call it "datasource"
and an EditText which I'll name "searchBox"

you'll also need to have a textWatcher, you can use this

Code:
    private TextWatcher filterTextWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            datasource.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

        }
    };

and at the end of your onCreate()
Code:
searchBox.addTextChangedListener(filterTextWatcher);

that should do it for you
 
Back
Top Bottom