Android :: Filtered List View With Custom Adapter Not Updated
Mar 25, 2010
I have a ListView with a custom Adapter that extends ArrayAdapter. It's 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?
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;
} }
View 5 Replies
Jul 23, 2009
Currently I am working on IM, and I am facing problem during implementations. I am implementing this messenger using XMPP client and using smack API for implementing all features like contacts list, online offline status, and chat also. Prblem which I am facing:
Its my list view where I am showing contacts list
public class ContactsList extends ListActivity implements OnClickListener{
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContactsManager manager = new ContactsManager(this); setListAdapter(manager);
} public class ContactsManager extends BaseAdapter{
private LayoutInflater mInflater; private Bitmap mainListIcons[];
private static ContactsInfo contactsInfo; public ContactsManager(Context context) {
mInflater = LayoutInflater.from(context); mainListIcons= new Bitmap[3];
mainListIcons[0] = BitmapFactory.decodeResource (context.getResources(), R.drawable.online);
mainListIcons[1] = BitmapFactory.decodeResource (context.getResources(), R.drawable.offline);
} @Override public int getCount() { return Global.contacts.size();//
contacts is vector where I am saving my contacts
} public Object getItem(int position) { return position;
} public long getItemId(int position) { return position;
} public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder; if (convertView == null) {
convertView = mInflater.inflate (R.layout.main_settings_lists_icon_text, null);
holder = new ViewHolder(); holder.mainListDisplayText = (TextView) convertView.findViewById(R.id.main_settings_lists_text);
holder.mainListDisplayIcon = (ImageView) convertView.findViewById(R.id.main_settings_lists_icon);
convertView.setTag(holder);}else{ holder = (ViewHolder) convertView.getTag();
} contactsInfo = (ContactsInfo)Global.contacts.elementAt (position);
String username = contactsInfo.getUsername(); String status = contactsInfo.getUserstatus();
if(status.equalsIgnoreCase("unavailable")) { older.mainListDisplayIcon.setImageBitmap(mainListIcons[1]);
}else{ holder.mainListDisplayIcon.setImageBitmap(mainListIcons[0]);
} holder.mainListDisplayText.setText(username); return convertView;
} static class ViewHolder { TextView mainListDisplayText;
ImageView mainListDisplayIcon;}
public class ContactsHandler implements RosterListener {
@Override public void entriesAdded(Collection<String> c) {
for(String s:c) { Log.i("ADDED Contacts",s);
} } @Override public void presenceChanged(Presence p) {
Log.i("PRESENCE",p.getFrom()); Log.i("IS Available",""+p.isAvailable());
Log.i("UserStatus",""+p.getStatus()); if(p.getFrom().contains("@") && p.isAvailable())
{ ChatManager chatmanager = Connection.getVopConnection getXMPPConnection().getChatManager();
Chat newChat = chatmanager.createChat("gulfam@imran-mehmood", new ChatHandler());
} } }
View 2 Replies
View Related
Aug 26, 2010
I have a list which shows data from a database using a cursor adapter. Using Menu option I am updating my database (inserting more rows deleting existing rows). When Menu operation completes, I want contents of list should show updated contents.
I have tried using cursor.requery(); (or explicitly querying cursor again) and using adapter.notifydatasetchanged(), but with this list of contents are not updated.
How can I refresh the contents of the list.
View 2 Replies
View Related
Jun 2, 2009
I developed a List View with a custom adapter (which extends Array Adapter). The problem is that i can't selected or highlighted items. Is there a attribute to fix in the list View Layout or something else?
View 22 Replies
View Related
Mar 4, 2010
Is there any way to show a message such as "No results" when i filter a list?
View 1 Replies
View Related
Nov 3, 2010
I am on Android 2.1 and I have one multi column Custom listview Using BaseAdapter with an editable edittext at the end of the listview. If the data in the listview do not contain the data of user choice then user should be able to enter data. If the data is already there in the list user will be able to select the data using custom selector. If a selection is made in the list view and user wanted to enter data in the text field at the bottom after selection then the marker in the list view should be unselected. I tried to use onclick() method on edit text using click listener. First time when it is clicked, edit text is getting focus and onclick() method is not fired. And when it is clicked second time, onclick() method is fired and notifyDataSetChanged() method is called. I tried to call the notifyDataSetChanged() method from the Focus Listener, list view selection is gone in my first attempt and edit text is not receiving any data input from the keyboard (frozen).
View 1 Replies
View Related
Sep 10, 2010
I have a custom list adapter contains a layout with controls in it. I was wondering how I can get each individual controls id? I am planning on changing the color of some textviews. code...
View 1 Replies
View Related
Oct 5, 2010
I have a ListView which is populated using a CursorAdapter. I'd also like to have some separators in my ListView. I have accomplished this with an ArrayAdapter, but I'm not sure how to accomplish this with a CursorAdapter. Are there any strategies for doing so? Or am I out of luck?
View 1 Replies
View Related
Jun 9, 2010
I have table with 3 columns which is binded to an XML document with three text views.
CODE:........
Depending on the value store in the third column, I have to decide whether i should display this row or not
How should, I go about with this.
This is what I have so far :
CODE:...............
View 2 Replies
View Related
Jul 12, 2010
I am calling one webservice.Result of webservice I am storing in an Array list. Result of webservice I want to display as list view. For ListView I am using SimpleAdapter. and SimpleAdapter is something like this:- SimpleAdapter adapter = new SimpleAdapter(this,hashmap, layout, from, to);
I am not able to put array list into hashmap. Is there anyway to do this?
View 2 Replies
View Related
Jan 31, 2009
I want to create custom View showing possibly several items. i think using Adapter interface would be good idea.
My question is: should i extend AdapterView? if so, what is the most imortant when doing this (e.g. AdapterView is ViewGroup, so how should i manage children)?
View 6 Replies
View Related
May 11, 2010
made a custom list adapter extending the Base adapter. Each item in the list has an imagebutton, 2 textviews and a button. I tried to add the context menu to the list so as to display some options for an item in the list. registerForContextMenu(getListView()); I used a MenuInflater object to inflate the context menu xml file. But on clicking the items in the list nothing shows up or the usual highlighting of the item of list on click isn't shown. Is it that the context menu doesn't work for custom list views? Any help would be much appreciated.
View 1 Replies
View Related
Dec 7, 2009
I have implemented a custom adapter the extends from the BaseAdapter and implements the getView method. It works fine except for one thing, not once do I get the convert View (a parameter to the getView method) that is not null (that can be reused).
View 2 Replies
View Related
Oct 13, 2010
I've got a schedule Class, which is simply a custom ViewGroup (with custom onMeasure() and onLayout()), which enables me to place childs(=events) with LayoutParams for column/row start and column/row end. The number of childs and their LayoutParams depend on database entries.
Now I'm trying to add childs (events) from my database. I'd have to use a Cursor Adapter, so my schedule Class has to extend ListView, right? I tried that but the newView() method of the adapter is never called. Why not? My custom ListView doesn't ask the adapter for childs, no childs are added. I also can't add the childs by hand calling schedule.addView() if I extend from AdapterView.
How can I add events to the schedule with the data from the cursor?
View 1 Replies
View Related
Mar 18, 2009
I have table with 3 columns which is binded to an XML document with three text views.
CODE:........
Depending on the value store in the third column, I want to change the text color in R.id.c. How should, I go about with this.
This is what I have so far :
COD:...............
View 3 Replies
View Related
Oct 28, 2010
I'm have a custom GridView Array Adapter. The problem for me is that when the grid list gets large enough to scroll off the screen the gridview and arraylist get out of sync. For instance in my case I have code that checks if an actor is of type director the text color should be red. if you scroll up and down my list enough times all the actors text in my gridview will become red. The thing is that the Gridview appearance actually looks fine its the backing data. Here is the complete class. In the code you can see where I tried to override getItem and getItemId but that didn't fix anything. Code...
View 6 Replies
View Related
Apr 16, 2010
I've seen example com.example.android.apis.view.List11 from ApiDemos. In that example, each row takes the view android.R.simple_list_item_multiple_choice. Each such view has a TextView and a CheckBox.
Now I want each view to have 2 TextView's and 1 CheckBox, somewhat similar to the List3 example. I tried creating a custom layout file row.xml like this:
CODE:...............
Then in Activity.onCreate(), I do like this:
CODE:..................
The result kind of looks like what I want, but it looks like the list doesn't know which item of it is selected. Also, I need to click exactly on the checkbox. In the List11 example, I only need to click on the item row.
So what do I need to do to make a multiple choice list with my custom view for each row?
View 2 Replies
View Related
Jun 3, 2010
I have a list view,each list item has a text view and a button. My onItemClick() for list item is not responding.But if i remove the button from list item it is responding.
View 3 Replies
View Related
Nov 4, 2010
As I am reviewing and prototyping my android project, I noticed that there is a view that has a list of items that are very customized. I have figured out most of my tools that I plan to use but I need some advice.
I have a list of items which can contain photos, some text to the right, an image to the bottom and more text below that. Very confusing I know. Each of these might be present for an item. The only thing that will always be there is the title.
So my question - what is the best way to create each custom list item view? I am thinking I have to use this getView to create each view. But when creating each view, is it best to 1) create a view dynamically and adding an image, for example, if it exists, or 2) create an xml file with all possible elements and hide them depending on the item?
View 2 Replies
View Related
Sep 15, 2010
can any body give example of multicolumn custom list view in android..
View 1 Replies
View Related
Jul 15, 2010
I am using one class which extends ListActivity and One class extending BaseAdapter.
The Base Adapter uses getView function to inflate layout from xml.
The xml contains a text and a button to delete the row of list.
Please let me know how to handle the button click in the ListActivity class.
View 1 Replies
View Related
Sep 2, 2010
I'm just beginning Android development, and I'm working to get a Custom list view with a checkbox working. I've created a base class that extends Activity, Created an Adapter and overrode the getView() method to add the checkbox to the list view. I'm assuming I need to do this because I need something equivalent to didSelectRowIndexAtPath from Obj C to update my model. Please let me know if there's an alternate way of doing this too Code...
View 2 Replies
View Related
Jan 20, 2010
Can anyone help with a problem I have? I created an activity (extending a list activity) and have it populating with a list of peoples names, however when I scroll up or down it automatically greys out the whole list view until you stop scrolling. Is it possible to stop this greying out from happening? I have attached an screenshot in case my description doesnt make sense. Code...
View 4 Replies
View Related
Nov 4, 2010
I have ListView with adapter class which extends ArrayAdapter and implements SectionIndexer. The problem is section indexer is not updated when adapter data is changed. Even if i add new elements the section remain the same. I tried some options setFaseScrollEnabled(false); setFaseScrollEnabled(true); but i got IndexOutOfBounds exception. So how can i update sectionIndexer when adapter's data is changed.
View 2 Replies
View Related
Aug 10, 2010
I must be missing something simple here.I've searched around but don't think my search query is touching on the right topics to yield results. Anyhow, what I'm after is running through the array of data I bind to a ListView after a "Submit" button has been clicked.
View 3 Replies
View Related
Aug 29, 2010
Im using ListView to to show some custom data, once data is updated in the adapter i call notifyDatasetChanged(), so the view will get updated, all of this works well, my issue though is i would like to run an animation once only on items that got changed when the adapter was updated. currently i keep a copy of all the changed objects and i tried to animate the correct items through the getView() call.
However if i do it only once for every getView call then i see no animation most of the time on items that changed. if i continue to do so in successive getView calls i see animation on items that don not change as well and also the ones that changed get animated again and again.
Im guessing sometimes android calls the getView() for other reasons than showing the generated view immediately, and thats the reason it doesnt work if i do it once.
View 1 Replies
View Related
Jun 18, 2010
I have seen examples implementing a custom Filter. The Android developer docs talk about implementing a Filterable interface. Does anyone have any advice and/or sample code on the best way to implement filtering in a ListView ?
View 2 Replies
View Related
Apr 4, 2010
I'd like to show another List View 'B' after clicking a item of List View 'A'. I use onListItemClick event in Android 1.6 project.
View 6 Replies
View Related
Jun 8, 2010
Is it possible to have a horizontal list view with an vertical list view? I would like to horizontal list scroll within a vertical list scroll.
View 13 Replies
View Related
Aug 2, 2010
I am trying to set up a ViewFlipper that changes a SlidingDrawers content each time a button is pressed. So far every view I set up worked fine, but now I am trying to create a ListView (including single_choice_mode) within a child view of the ViewFlipper, but my attempt only let to a NullPointerException. As I only discovered ViewFlipper today, I am not yet familiar with it and may not have understood it completely. if someone could give me a hand and help me find out what I have done wrong, that would be great. Here is what I have done:
The code for the onClick event of the ImageButtons:
public void onClick(View v){
if (v == btnExposure){
mFlipper.setDisplayedChild(0); }
else if (v == btnProperties){
mFlipper.setDisplayedChild(1);}
else if (v == btnSpecialEffects){
mFlipper.setDisplayedChild(2);.............
View 1 Replies
View Related