Android search list while typing

后端 未结 5 995
名媛妹妹
名媛妹妹 2020-12-04 15:06

How can I build a search bar where while I\'m typing the results are shown in the ListView in which I\'m searching?

For example, I have a list view with

5条回答
  •  无人及你
    2020-12-04 15:24

    You can't do this with the search bar. But the listview has a possibility to filter on key pressed, like it is done in the contacts. The user simply starts typing and the list gets filtered then. Filtering is not really like searching. If you list contains the word foo somewhere and you type oo foo will be filtered out, but if you type fo it will stay even if the list item is call bar foo.

    You simply have to enable it:

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    

    I don't know how this is done if you don't have a hardware keyboard. I'm using the droid and starting to type starts the list to filter and to show only matching results.

提交回复
热议问题