views:

136

answers:

2

My ListView have more than 3000 rows. And when I typing on EditText to filter data in my ListView it run slowly. Look at my code here

final TextWatcher textChecker = new TextWatcher() {
    public void afterTextChanged(Editable s) {}

    public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {}

    public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

        filterData(search.getText().toString());

    }
};

private void filterData(String textinput){
 mCursor = mHelperData.searchData(textinput);
 startManagingCursor(mCursor);

 String[] from = new String[]{ MyData.KEY_ROWID,
   MyData.KEY_TITLE, MyData.KEY_DESCRIPTION };

 int[] to = new int[]{ R.id.id, R.id.title, R.id.description, R.id.icon };  
 setListAdapter(new MyAdapter(this, R.layout.list_row, mCursor, from, to ));
}

I think retrieve data with Cursor is not a good way here. So, Is there any better way to improve the speech in this case?

+2  A: 

Come up with a navigation pattern that does not involve the user having to scroll through or filter 3000 rows.

Scrolling through or filtering 3000 rows would be very annoying on a quad-core desktop with 4GB of RAM, continuous AC power, a 19" LCD, a full-size keyboard, and a standard mouse.

Similarly, no Web site worth mentioning dumps 3000 entries on a user in a single page...and people using Web browsers are still using full size screens, keyboards, and mice in many instances.

Sifting through 3000 rows on a phone is insane. Do not make users do that. For example, divide those 3000 rows into categories, and have the user pick a category first.

CommonsWare
+1 for helping developers think of what's best/easiest for *users* not developers
I82Much
Yeah, It's really hard for user to scroll through 3000 rows with a phone screen. But my application here is just use for "Search" purpose. Anyway, your answer give me some inspire and I think maybe I could make something different here. Thank you so much!
Dennie
If your application is just for searching, do not put 3000 items in a list. Instead, just provide a search field, run a search, and show results. Case in point: when you search the Android Market, you do not get a ListView of all applications in the Market which then get filtered. Instead, you get a search field and only get a ListView showing matching results.
CommonsWare
You know, I'm going to step up to the plate here and say sometimes it's not an option to cut down. I finished an app where the customer has thousands of rows of data across multiple DB's and provides a search function. 99% of users use the search but the customer still wanted the ability to scroll through the entire listing and still have it be fast. Sometimes you have to do what the customer wants even if your peers and the platform experts give you a hard time about it.
MattC
At first times, I came up with the idea "give user a search box and return the result in a listview" and I had done that. But let take a look at "Smart Contact Search" on Android phone. It's really make sense! The only thing I have faced here is "3000 rows slowly".
Dennie
+1  A: 

Just to add to Marks answer - I recently faced the same problem and came up with tutorial on Androidguys.com which demonstrates how one can code an "endless" list

DroidIn.net