我正在使用android中的列表視圖。 我想爲列表視圖中的每個項目設置背景顏色。在列表視圖中爲項目設置背景
如果我使用setbackgroudcolor函數,它顯示不正確的顏色。看起來有應用背景和新顏色的混合顏色。 如果我使用setbackgroundresource基金,它顯示ok。但是,當我點擊一個項目時,顏色不會改變。
我需要設置背景對列表視圖中的每個項目,當點擊一個項目,背景改爲其他顏色或背景
我的代碼:OnView
// Set background
RelativeLayout root = (RelativeLayout) vi.findViewById(R.id.p60001_layout_info);
if (position % 2 == 0){
root.setBackgroundResource(R.drawable.cell_g_02);
//root.setBackgroundColor(R.color.color_fist_in_pack_view);
}else{
root.setBackgroundResource(R.drawable.cell_g_01);
//root.setBackgroundColor(R.color.color_fist_in_pack_view);
}
行佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/p60001_layout_info"
android:layout_width="match_parent"
android:layout_height="30dp">
<TextView
android:id="@+id/p60001_item_info"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="15dp" android:layout_marginLeft="10dp" android:fadeScrollbars="false" android:textColor="@color/txt_normal" android:scrollHorizontally="true" android:gravity="center_vertical">
</TextView>
<ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/arrow" android:layout_marginRight="15dp"/>
<ImageView
android:id="@+id/p60001_image_notice_num"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_marginRight="30dp"
android:layout_toLeftOf="@+id/icon"
android:layout_marginTop="5dp" android:src="@drawable/fukidashi" android:visibility="invisible" android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" android:longClickable="false"/>
<TextView
android:id="@+id/p60001_item_notices"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/icon"
android:ems="10" android:layout_marginRight="40dp" android:background="@android:color/transparent" android:freezesText="false" android:focusableInTouchMode="false" android:focusable="false" android:clickable="false" android:selectAllOnFocus="false" android:textSize="20px" android:layout_marginTop="4dp" android:visibility="invisible">
<requestFocus />
</TextView>
</RelativeLayout>
您使用的自定義適配器 – 2012-04-13 02:16:44