0

Table の 2 ペイン UI を設計しました。左ペインにはリスト ビューが表示され、右ペインにはリストの詳細が表示されています。ユーザーがクリックしたリスト行を選択して表示し、その表示を右ペインに表示したいと考えています。

そのため、アイテムを選択するために以下のコードを設定しています。

 android:choiceMode="singleChoice"
 android:background="@drawable/selector_list_view"

リストのレイアウトは以下のレイアウト ファイルにあります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp"
android:background="@drawable/bg_dialog_fragment">


    <Button     
        android:id="@+id/SortByTitle"
        android:layout_width="0dip"
        android:textColor="@color/solid_black"
        android:background="@drawable/sort_button_selected"
        android:layout_height="wrap_content"
        android:layout_marginRight="0dip"
        android:paddingTop="5dip"
        android:paddingBottom="5dip"
        android:paddingRight="8dip"
        android:textSize="15sp"
        android:textStyle="bold"
        android:layout_weight="0.5"
        android:text="@string/project"
        android:drawablePadding="5dip"
        android:drawableRight="@drawable/up_arrow"/>
    <Button
        android:id="@+id/SortByDate" 
        android:textColor="@color/solid_black"
        android:background="@drawable/sort_button_unselected"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:layout_marginLeft="0dip"
        android:paddingBottom="5dip"
        android:textStyle="bold"
        android:textSize="15sp"
        android:layout_weight="0.5"
        android:drawablePadding="5dip"
        android:paddingRight="8dip"
        android:text="@string/due_date"/>
</LinearLayout>

<TextView
    android:paddingRight="1dp"        
    android:layout_marginRight="1dp"
    android:id="@+id/TextViewTitle"
    style="@style/title_style"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/SortOrder"
    android:text="@string/workflow_incourt" />

  <RelativeLayout
    android:layout_marginRight="1dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/SearchFooter"
    android:layout_below="@+id/TextViewTitle"
    android:background="@color/solid_white"
   >

    <ListView
        android:id="@+id/ListViewProject"
        style="@style/listview_style"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:choiceMode="singleChoice"
        android:background="@drawable/selector_list_view" />

</RelativeLayout>

そして、ドローアブルは

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:state_focused="true" android:drawable="@android:color/background_dark" />
<item android:state_checked="true" android:state_focused="false" android:drawable="@android:color/background_dark" />
<item android:state_selected="true" android:drawable="@android:color/background_dark"/>
<item android:state_checkable="true" android:drawable="@android:color/background_dark"/>

しかし、それでもリスト行が選択されているように表示されていません。これを達成するために、さらに何をする必要がありますか。

選択したアイテムのスクリーンショットも添付されています。ここに画像の説明を入力

4

1 に答える 1

0

選択したアイテムIDを1つの変数で追跡できると思います。次に:

  • IDが設定した保存済みのものと一致する場合のアダプタのGetView(例:赤色)
  • OnListItemClickListenerは、古いIDを新しいIDrefに置き換えることで消去します
于 2012-05-26T14:37:22.333 に答える