49

私の目的はそのようなものを手に入れることです:
http://appsreviews.com/wp-content/uploads/2010/08/Cures-AZ-App-for-iPhone.jpg

しかし、私が見つけることができる唯一の例は、そのようなリストです:
android-iPhoneの連絡先アクティビティのようにアルファベットでlistviewfastscroll

明らかに、高速スクロール時に文字を表示する連絡先のようなリストは必要ありません。私はこれを行う方法を知っています。

どんなポインタでも大歓迎です。(私はこれを試しましたが、成功しませんでした)

以下に、FunkTheMonkによって提案された完全なソリューション(どうもありがとう):

通常どおりリストビューを定義します。を含むRelativeLayoutを定義ListViewし、右側にLinearLayoutすべての文字を含むaを定義します。より良い解決策として、文字のリストを動的に生成して、リスト内の文字のみを表示することができます。次に、onClickメソッドで、リストをスクロールする動作を追加します。

xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="28dip" />

    <LinearLayout android:orientation="vertical"
        android:layout_width="28dip" android:layout_height="wrap_content"
        android:layout_alignParentRight="true" android:background="@android:color/transparent" >

        <TextView android:id="@+id/A" android:text="A" android:tag="A"
            style="@style/alphabetTextView"/>
        <TextView android:id="@+id/B" android:text="B" android:tag="B"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/C" android:text="C" android:tag="C"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/D" android:text="D" android:tag="D"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/E" android:text="E" android:tag="E"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/F" android:text="F" android:tag="F"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/G" android:text="G" android:tag="G"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/H" android:text="H" android:tag="H"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/I" android:text="I" android:tag="I"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/J" android:text="J" android:tag="J"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/K" android:text="K" android:tag="K"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/L" android:text="L" android:tag="L"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/M" android:text="M" android:tag="M"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/N" android:text="N" android:tag="N"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/O" android:text="O" android:tag="O"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/P" android:text="P" android:tag="P"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/Q" android:text="Q" android:tag="Q"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/R" android:text="R" android:tag="R"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/S" android:text="S" android:tag="S"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/T" android:text="T" android:tag="T"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/U" android:text="U" android:tag="U"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/V" android:text="V" android:tag="V"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/W" android:text="W" android:tag="W"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/X" android:text="X" android:tag="X"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/Y" android:text="Y" android:tag="Y"
            style="@style/alphabetTextView" />
        <TextView android:id="@+id/Z" android:text="Z" android:tag="Z"
            style="@style/alphabetTextView" />

    </LinearLayout>
</RelativeLayout>

Java

@Override
public void onClick(View v) {
    String firstLetter = (String) v.getTag();
    int index = 0;
    if (stringList != null) {
        for (String string : stringList) {
            if (string.startsWith(firstLetter)) {
                index = stringList.indexOf(string);
                break;
            }
        }
    }
    lv.setSelectionFromTop(index, 0);
}
4

2 に答える 2

44

これはiPhoneの機能であり、Androidは高速スクロールを使用します。一般的な機能を強制するのではなく、プラットフォームの代替手段を使用することをお勧めします。

必要な場合は、これを自分で実装する必要があります。リストビューをRelativeLayoutに配置し、AZTextViewsをに設定された垂直LinearLayoutに配置しlayout_alignParentRight="true"ます。TextViewのタグを適切にAZに設定onClick="quickScroll"し、それらすべてに設定します。

アクティビティに実装する:

public void quickScroll(View v) {
    String alphabet = (String)v.getTag();
    //find the index of the separator row view
    list.setSelectionFromTop(index, 0);
}

これにより、選択した文字onClickまでスクロールしますが、iPhoneでアルファベットの上を指でスクロールすると、リストが更新されると思いますか?そのためには、onClickListenerではなくonTouchListenerを実装する必要があります。

于 2011-11-25T10:46:31.593 に答える
25

IndexScrollerタッチでのみ表示され、接触がない場合は自動的に非表示になるものを使用してみることができます。これがスクリーンショットです

スクリーンショット

于 2012-07-24T09:38:53.647 に答える