sir, how can i refresh my custom listview using baseadapter. i don\'t know what to place, or where to place it in my code. please help me. thanks in advance
Two options: either hold onto the reference for the ArrayList
that you passed into the constructor so you can modify the actual list data later (since the list isn't copied, modifying the data outside the Adapter still updates the pointer the Adapter is referencing), or rewrite the Adapter to allow the list to be reset to another object.
In either case, after the ArrayList
has changed, you must call notifyDataSetChanged()
to update your ListView
with the changes. This can be done inside or outside the adapter. So, for example:
public class MyCustomBaseAdapter extends BaseAdapter {
//TIP: Don't make this static, that's just a bad idea
private ArrayList searchArrayList;
private LayoutInflater mInflater;
public MyCustomBaseAdapter(Context context, ArrayList initialResults) {
searchArrayList = initialResults;
mInflater = LayoutInflater.from(context);
}
public void updateResults(ArrayList results) {
searchArrayList = results;
//Triggers the list update
notifyDataSetChanged();
}
/* ...The rest of your code that I failed to copy over... */
}
HTH