开发者

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 befor开发者_运维问答e the text (like in the android contacts list, there is an image of the person, then their name).

Many thanks, Todd


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜