2015-01-03 4 views
0

간단한 상점 목록 앱. 1 활동. 1 사용자 정의 어댑터. 1 listview. TextViewCheckBox와 사용자 정의 행 :체크 박스가있는 사용자 정의 목록보기. 맞춤 어댑터

의 ListView :

<ListView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/shopListView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentEnd="false" 
    android:layout_alignParentBottom="false" 
    android:layout_below="@+id/toolbar"/> 

사용자 정의 행 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/shopListItem"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Test TEST" 
     android:id="@+id/itemTextView" 
     android:layout_gravity="start" 
     android:textSize="25sp" 
     android:paddingLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:layout_marginBottom="5dp" /> 

    <LinearLayout android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignBottom="@id/itemTextView" 
     android:layout_alignParentRight="true"> 
     <CheckBox 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/doneCheckBox" 
      android:checked="false" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      android:layout_gravity="center"/> 
    </LinearLayout> 
</RelativeLayout> 

내 자신의 어댑터 (BaseAdapter를 확장) :

,

항목 : 당신이 볼 수있는 ArrayList "ShopItems"에 저장

public class ShopItem { 

    private String description; 
    private boolean done; 

    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    public boolean isDone() { 
     return done; 
    } 

    public void setDone(boolean done) { 
     this.done = done; 
    } 
} 

항목 (ShopItem).

내가 원하는 것은 : CheckBox 클릭 내 항목 "isDone - true"로 만드는 텍스트 뷰와 텍스트 색상을 변경합니다 (정확하게에하지 목록보기 항목을 클릭합니다.). 내 개체에 영향을주고 isDone 부울을 변경하면 OnCheckedChangeListener이 필요합니다.

는 질문 :

와는 어떻게 OnCheckedChangeListener를 넣을 수 있습니다?

+0

를 사용하여 체크 박스 상태를 유지() 메소드 customadapter –

+0

내부의 getView에서 OnCheckedChangeListner을()() 쓰기 – KomalG

+0

http://stackoverflow.com/ 질문/26190444/how-to-update-the-textview-text-state-of-a-checkbox-in-listview 내 대답을 보니 문제가 해결됩니다. –

답변

2

//의 getView() 안의 당신의 getView 안에 목록

doneCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      if(isChecked){ 
       doneCheckBox.ischecked=true; 
      } 
      else{ 
       doneCheckBox.ischecked=false; 
      } 
     } 
    }); 
관련 문제