views:

254

answers:

1

I'm writing my first android app (I'm a noob at android, but decent at java). The first screen of the app consists of a huge list (about 1.5K items) of Manga-objects. The code I use is as following:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"&gt;
        <ListView android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:id="@+id/android:list"></ListView>
        <TextView android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:text="@string/list_no_items"
            android:id="@+id/android:empty"></TextView>
</LinearLayout>

row.xml:

<LinearLayout android:id="@+id/LinearLayout01"
              android:layout_width="fill_parent" 
              android:layout_height="?android:attr/listPreferredItemHeight"
              android:padding="6dip"
              xmlns:android="http://schemas.android.com/apk/res/android"&gt;
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:src="@drawable/icon" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/toptext"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
        />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" 
            android:id="@+id/bottomtext"
            android:singleLine="true"
            android:ellipsize="marquee"
        />
    </LinearLayout>
</LinearLayout>

Then I have a adapter which basically takes a Manga-object and puts it's name in the rows toptext, and it's latest updated date in the bottomtext. However, (this might be caused by the virtualization of the unit though), the result is really slow. Scrolling the list takes forever and you can only scroll small peaces of the time. How can I make the list work like the one in the contacts-app? So that when you start scrolling a handle pops out at the right side of the screen, and when you drag it letters shows up as of how far you've scrolled (the list is sorted alphabetically), and also, is there a way I could improve the performance of the list?

+2  A: 

To add the thumb scroller, adjust your ListView in your main.xml like so:

<ListView android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:id="@+id/android:list"
        android:fastScrollEnabled="true"></ListView>

Adding the android:fastScrollEnabled="true" attribute.

http://developer.android.com/intl/de/reference/android/widget/AbsListView.html#attr_android:fastScrollEnabled

You may also look at using a SectionIndexer

http://developer.android.com/intl/de/reference/android/widget/SectionIndexer.html

Jim Blackler