«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

올해는 머신러닝이다.

ListView 에서 아이템 클릭시 주황색 화면 변경하는 예제 본문

Android/Tip&Tech

ListView 에서 아이템 클릭시 주황색 화면 변경하는 예제

행복한 수지아빠 2011. 7. 7. 18:30

File: res/layout/main.xml


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<ListView

android:id="@android:id/list"

android:layout_width="wrap_content"

android:layout_height="wrap_content" android:listSelector="@android:color/transparent" />

<TextView

android:id="@android:id/empty"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/empty" />

</LinearLayout>

 

 

 

 

File: res/layout/item.xml

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

android:layout_height="fill_parent"

android:orientation="horizontal" android:padding="10sp" android:background="@drawable/item_selector">

 <CheckBox

android:id="@+id/checkbox"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:focusable="false" />

<TextView android:id="@+id/title"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:ellipsize="end"

android:singleLine="true"

android:textStyle="bold"

android:padding="7dip"

android:textSize="18sp"

android:layout_toRightOf="@id/checkbox"

android:textColor="@color/black" />

</RelativeLayout>

 

 

 

File: res/drawable/item_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/green" />
<item android:state_selected="true" android:drawable="@color/blue" />
<item android:drawable="@color/white" /></selector>
 
 

File: res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<color name="red">#ff00</color>

<color name="green">#f0f0</color>

<color name="blue">#f00f</color>

<color name="white">#ffff</color>

<color name="black">#f000</color>

</resources>