Todd Davies
Todd Davies

Reputation: 5522

Android list view: how to use fast scrolling and alphabetical ordering

I'm fairly new to Android programming, although not programming in other languages (if that makes sense).

I've got a string array like this:

static final String[] fruit = new String[] {"carrot", "banana", "apple"};

I want to display this in a list view, that is easily scrolled through using fast scroll and is in alphabetical order. I have found a few partial solutions on stack overflow, but I can't get them to work with a String[] (they want arrays of objects) and I also want to be able to have an image of the fruit before the text (like in the android contacts list, there is an image of the person, then their name).

Many thanks, Todd

Upvotes: 1

Views: 1183

Answers (2)

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

To make it in alphabetical order, you must do it in the data you use to populate the view.

To draw the image next to the text you can do it by creating an layout for the row itens and override the getView of the ArrayAdapter.

Upvotes: 1

scambione
scambione

Reputation: 71

I might be wrong, but i think that the main problem here is to order the array, isn't it?

because with a code like this you could easily view an array of strings as a list

your class has to extend ListView then you can write:

String[] fruit = new String[] {"carrot", "banana", "apple"};   
ArrayAdapter<String> list_adapt = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, fruit);
setListAdapter(list_adapt);
list=getListView();

if you want to order the array you will have to create a sorting method

Upvotes: 1

Related Questions