Why do you want to put an edittext, listview already have an keystroke filter.
I have a similar problem because my listview is not filtering, even implementing the toString method os the class from my custom Adapter. Ialso have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter of the Type User On Mar 25, 9:45 am, Anton Pirker <an...@ignaz.at> wrote: > Hi! > > Kumar Bibek wrote: > > What exactly are you trying to do? Can you please explain? > > What i am trying to do: > > I want to have a EditText and below my list with about 1200 Artistnames. > If the user enters something in the EditText i want to filter the > artists according to the entered text. > > So if the user enters "sa" only artists with a name that contains "sa" > are displayed in the list. The list should be updated on every keystroke. > > I think this is a fairly common problem and i hav read a lot of solution > on the internet, but it is just not working with my code (see below) > According to my Log.d() Message the artists are filtered, but the list > does not change, its not updated! Do you know whats wrong with my code? > > Thanks! > Anton > > > > > Thanks and Regards, > > Kumar Bibek > > > On Mar 25, 3:17 pm, Anton Pirker <an...@ignaz.at> wrote: > > >> Hi! > > >> I have a ListView with a custom Adapter that extends ArrayAdapter. It's > >> a ArrayAdapter of Type Artist. (There are about 1200 artists in my list) > > >> Artist is a very small class that has a name and an id. The Artist Class > >> has toString() overridden to return just the name. > > >> I have an EditText. The EditText has an TextChangeListener where i call > >> .getFilter().filter(chars, callback) on my adapter. > > >> In the Filter.Filterlistener().onComplete() callback i print the count > >> and it looks really good. As i type the count decreases. So it seams > >> everything works as advertised, but the List stays the same. I tried to > >> call artistAdapter.notifyDataSetChanged() to force the list to redraw, > >> but nothing happens. [see 2.)] > > >> I am tinkering around for days now! I am desperate.. Hopefully someone > >> can have a look on my code and tell me what i am doing wrong! How can i > >> force the list to be redrawn? > > >> Thanks! > > >> (I have posted this question also on > >> stackoverflow:http://stackoverflow.com/questions/2505800/filtered-listview-not-updated) > > >> Here is what i have done: > > >> 1.) Defined a ListView and an EditText like this: > > >> <EditText xmlns:android="http://schemas.android.com/apk/res/android" > >> android:id="@+id/list_search_text" > >> android:layout_width="fill_parent" > >> android:layout_height="35dip" > >> android:layout_below="@id/header"> > >> </EditText> > >> <ListView xmlns:android="http://schemas.android.com/apk/res/android" > >> android:id="@+id/list_search" > >> android:layout_width="fill_parent" > >> android:layout_height="fill_parent"> > >> </ListView> > > >> 2.) Setup my ListView in the Activities onCreate(): > > >> private ListView listView = null; > >> private ArtistAdapter artistAdapter = null; > > >> @Override > >> protected void onCreate(Bundle savedInstanceState) { > >> super.onCreate(savedInstanceState); > >> setContentView(R.layout.search_artists); > > >> artistAdapter = new ArtistAdapter(this, R.layout.row, list); // > >> 'list' is an ArrayList<Artist> > > >> listView = (ListView) findViewById(R.id.list_search); > >> listView.setAdapter(artistAdapter); > >> listView.setFastScrollEnabled(true); > >> listView.setTextFilterEnabled(true); > > >> listView.setOnItemClickListener(new OnItemClickListener() { > >> public void onItemClick(AdapterView<?> av, View v, int > >> position, long id) { > >> // do something > >> } > >> }); > > >> EditText txtSearch = (EditText) > >> findViewById(R.id.list_search_text); > >> txtSearch.addTextChangedListener(new TextWatcher() { > >> public void afterTextChanged(Editable arg0) { } > > >> public void beforeTextChanged(CharSequence arg0, int arg1, > >> int arg2, int arg3) { } > > >> public void onTextChanged(CharSequence chars, int start, int > >> before, int count) { > >> artistAdapter.getFilter().filter(chars, new > >> Filter.FilterListener() { > >> public void onFilterComplete(int count) { > >> Log.d(Config.LOG_TAG, "filter complete! count: " > >> + count); > >> artistAdapter.notifyDataSetChanged(); > >> } > >> }); > >> } > >> }); > >> } > > >> 3.) This is my ArtistAdapter in short. I added an remove() and add() > >> method: > > >> public class ArtistAdapter extends ArrayAdapter<Artist> implements > >> SectionIndexer { > >> private List<Artist> items; > > >> /* other stuff like overridden getView, getPositionForSection, > >> getSectionForPosition and so on */ > > >> @Override > >> public void remove(Artist object) { > >> super.remove(object); > >> items.remove(object); > >> } > > >> @Override > >> public void add(Artist object) { > >> super.add(object); > >> items.add(object); > >> } > >> } > > >> 4.) My artist has also the toString() overridden: > > >> public class Artist implements Comparable<Artist> { > >> public String uid; > >> public String name; > > >> public Artist(String id, String name) { > >> this.uid = id; > >> this.name = name; > >> } > > >> public int compareTo(Artist another) { > >> return this.name.compareToIgnoreCase(another.name); > >> } > > >> @Override > >> public String toString() { > >> return this.name; > >> } > >> } > > >> -- > >> DI(FH) Anton Pirker > > >> ------------------------------ > >> cross platform mobile software > >> burggasse 123/53 > >> a-1070 wien > >> tel: +43 699 1234 0 456 > >> skype: antonpirker > > >>http://anton-pirker.at > > -- > DI(FH) Anton Pirker > > ------------------------------ > cross platform mobile software > burggasse 123/53 > a-1070 wien > tel: +43 699 1234 0 456 > skype: antonpirker > > http://anton-pirker.at -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.