Android Listview Filtering versus Repopulation

after some advice really. My app fills a list view on load using a mediastore cursor. This is pulling music linked to user defined folder, which in most cases will be all of their stored music. I have one beta tester that is using an Archos Tablet with approximately 10000 songs on it, running android 2.2. While performance for most users is pretty slick, I wanted to improve the experience for users such as this.

The current process:

User loads app. App finds default folder App populates list view with music within and below that folder User moves to a folder further down the tree, list view is repopulated based on the selected folder User moves again....list is repopulated based on the selected folder...

So what I'm wondering is this - is it faster/more efficient to use the following process: User loads app App finds default folder app populates list view with music within and below that folder user moves to a folder within the tree, THE LIST IS FILTERED TO THAT FOLDER if the user moves higher up the tree than the default data (i.e. potential for new files), the list view is repopulated, but only in this circumstance.

So basically,my questions is "how does filtering compare to repopulation?"


A very good question. Let me try to answer this.

Filtering is actually repopulation the ListView, whereas you create/get a new collection and tell the Adapter it's content has changed by calling notifyDataSetChanged.

The 'heavy' work for a listView is that getView call in it's adapter. I've tested this myself, and if you inflate a new View every time getView is called, the performance drops. Heavenly.

The ListView's adapter is built so that already inflated views can be re-used, which tackles above named problem. Besides, only visible views are loaded, so it's not like the Adapter is going to create 10000 views if you tell it's collection is 10000 items big.

notifyDataSetChanged will tell the adapter to rebuild the listviews content, but it still contains previously inflated views. So here is a big performance win.

So my advice for you is, when you are using the same 'row layout' to just repopulate the ListView using notifyDataSetChanged. I've implemented this multiple times myself without noticing any UI performance issues. Just make sure to do the filtering of your collection an a background thread. (AsyncTask comes in handy here).

One last tip: Do you have any phone thats quite old? Or someone you know does? Find the slowest phone you can and test your application on it for performance. I have a HTC Legend myself, which is outdated and slow if f*ck, but perfect for performance testing. If it runs on my (old) phone, it runs on any phone.

Pseudo code sample if your applications flow:

public class FolderListActivity extends Activity implements OnItemSelected {


    private ListView listView
    private Adapter adapter;

    protected void onCreate(Bundle savedInstanceState) {

        // setContentView here 
        listView = (ListView)findViewById(;

    public class AsyncLoadMusicLocationTask extends AsyncTask<Void, Void, List<String>> {

        public List<String> doInBackground(Void... params) {
            // Load the information here, this happens in the background
            // using that cursor, i'm not sure what kind of things you are using
            // So I assumed a List of Strings

        public void onPostExecute(List<String> result) {
            // Here we have our collection that was retrieved in a background thread
            // This is on the UI thread

            // Create the listviews adapter here
            adapter = new Adapter(result, and other parameters);

    public void onItemSelect(Some params, not sure which) {


        List<String> collection = adapter.getObjects();
        for (int i = 0; i < collection.size(); i++) {
            // Filter here

// this method will most probably not exist, so you will need to implement your own Adapter class

Need Your Help

Redirect loop in urlrewrite (Tomcat)

tomcat redirect https tuckey-urlrewrite-filter

I'm implementing a redirect in Tomcat with urlrewite filter to force https in a page, but the rule I created is causing a redirect loop.