2011-08-14 9 views
1

로드 할 사용자 정의 행을 얻으려고 하루 종일 보냈습니다. StackOverflow와 다른 곳에서 안드로이드리스트 뷰 내의 데이터 행에 체크 박스를 바인딩하는 방법에 대한 많은 예제가있는 것처럼 보이지만 모두 불완전한 것처럼 보입니다.확인란이있는 Android ListView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="40dip" 
    android:orientation="horizontal" android:background="@drawable/row_bk" 
    android:layout_gravity="center_vertical"> 

    <TextView android:id="@+id/ItemID" 
    android:layout_weight="0" android:visibility="gone" 
     android:layout_width="0dp" android:gravity="center" 
    android:layout_height="wrap_content" /> 

<TextView android:id="@+id/Title" 
    android:layout_width="0dp" android:textColor="#666" 
    android:layout_weight="1" android:layout_height="40dip" 
    android:padding="5dp" android:gravity="center_vertical" 
    android:textSize="17dip" /> 

<CheckBox android:id="@+id/chkCheck" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="false" android:clickable="true"></CheckBox> 

</LinearLayout> 

코드에서, 나는리스트 뷰를 채우는하는 SimpleCursorAdapter 있습니다

는 여기에 내가 (row.xml)가 무엇.

Cursor oLoop = db 
      .rawQuery(
      "select _id, title, is_checked from tbl",null); 

    startManagingCursor(oLoop); 

    String[] from = new String[] { "_id", "title", "is_checked" }; 

    int[] to = new int[] { R.id.ItemID, R.id.Title, R.id.chkCheck }; 

    SimpleCursorAdapter oList = 
    new SimpleCursorAdapter (this, R.layout.task_item_row, oLoop, from, 
    to); 

    setListAdapter(oList); 

과거에는 무엇을해야할지 모르겠습니다. 누군가가 좋은 모범을 보일 수 있다면, 좋을 것입니다. 목표는 실제로 체크 박스를 토글 할 수있게하는 것입니다.

미리 감사드립니다.

getViewAdapter().setViewBinder(
    new ViewBinder(){ 
     public boolean setViewAdapter(View view, Cursor cursor, int columnIndex){ 
      <JavaType> object = cursor.get<JavaType>(columnIndex); 

      boolean isHandled = false; 
      if(view.getId() == R.id.checkBox){ 
       CheckBox cb = (CheckBox) view; 
       cb.setChecked(isObjectChecked(object)); 
       // object depends on your underlying data type 
       // in the data base, use the debugger to find the actually implemented type. 
       isHandled = true; 
      } 

      return isHandled; 
     } 
    } 
); 

이 조건부 보이는 전망과 로딩 매우 강력한 방법이 될 수 있습니다 알렉스

답변

1

알렉스,

다음 단계는 다음과 같이 보일 것이다 ViewBinder.setViewValue()

을 구현하는 것입니다 우리의 네트워크에서 등

+0

그래, 그랬어! 그것은 내가 놓치고 있었던 조각이었다!! 분명히, 분명한 단계도 아닙니다. 나는 이것을 어딘가에서 후손을 위해 문서화해야 할 것이다. – LTMOD

+0

@LTMOD [SimpleAdapter] (http://developer.android.com/reference/android/widget/SimpleAdapter.html) 문서에 있습니다. –