main.xml에서 ListView를 구현하였고, list_item.xml을 만들어 Image + Text로 ListView를 구현하였습니다.

 

그런데 여기서 궁금한점은 어떻게하면 각각의 List들을 클릭할 때, 체크박스처럼 이미지를 바꿀 수 있는지 궁금합니다.

 

결국 체크박스를 내가 원하는 이미지로 구현하는건데요, 어떠한 방법과 코드들이 필요한지 궁금합니다.

 

java코드

ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.list_item, R.id.txt_noti_title, list);
       ListView listView = (ListView) layout.findViewById(R.id.listview);
       listView.setAdapter(adapter);

       listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        public void onItemClick(AdapterView<?> list, View v, int position, long id){
         
        }
       });

 

main.xml 코드

 

<LinearLayout
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content">
    <ListView
     android:id="@+id/listview"
     android:padding="5dip"
     android:layout_width="fill_parent"
     android:layout_height="200dip"/> 
      </LinearLayout>

 

list_item 코드

 

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="18pt"
  android:orientation="horizontal">
   <ImageView
   android:layout_marginLeft="5dip"
   android:layout_marginTop="10dip"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:background="@drawable/bg_check_off"
   android:layout_weight="8"
   android:id="@+id/img"
   />
  <TextView
    android:layout_marginLeft="10dip"
   android:layout_marginTop="10dip"
   android:id="@+id/txt_noti_title"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_weight="1"/>
</LinearLayout>