ListView があり、リストで選択した項目の色を変更したいと考えています。以下の選択したアイテムの色を変更できますが、他のすべてのアイテムの色を元の色に戻す (または変更する) にはどうすればよいですか?
@Override
public void onListItemClick(ListView parent, View v, int position, long id)
v.setBackgroundColor(Color.CYAN);
}
親の色を変更しようとしましたが、アイテムの色は変わりません:
@Override
public void onListItemClick(ListView parent, View v, int position, long id)
parent.setBackgroundColor(Color.WHITE);
v.setBackgroundColor(Color.CYAN);
}
リストビュー:
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:drawSelectorOnTop="false" />
各項目は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contacts_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout android:id="@+id/linear"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text=""/>
<TextView
android:id="@+id/lastname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginLeft="3sp"
android:text=""/>
<TextView
android:id="@+id/firstname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginLeft="3sp"
android:text=""/>
<TextView
android:id="@+id/sipExt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#59696E"
android:gravity="right"
android:layout_marginRight="9dp"
android:textStyle="italic"
android:text=""/>
</LinearLayout>
<TextView
android:id="@+id/alias"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#a69d86"
android:textStyle="italic"
android:layout_below="@id/linear"
android:text=""/>