2016-10-29 2 views
0

Android 개발 초보자입니다.커서에서 simple_list_item_checked의 확인란을 설정하십시오.

유형이 android.R.layout.simple_list_item_checked 인 ListView가 있고 이름이 "CHECKED"인 내 Cursor에있는 값으로 확인란을 설정하려고합니다. 문제는 확인란의 ID를 찾을 수 없다는 것입니다. (android.R.id.checkbox를 시도했지만 작동하지 않았습니다.) 커서 커서를 기반으로 설정하는 방법을 모르겠습니다. 커서는 SQLite 데이터베이스 테이블에서 생성되며 "CHECKED"열은 BOOLEAN 유형입니다.

내 코드가 작동하지 않습니다 :

lv.setAdapter(
       new SimpleCursorAdapter(MainActivity.this, android.R.layout.simple_list_item_checked, mCursor, 
         new String[]{"NOTES", "CHECKED"}, new int[]{android.R.id.text1, android.R.id.checkbox}, 0)); 

당신이 좀 도와 주 시겠어요을? 미리 감사드립니다. 당신이 R.layout.simple_list_item_checked xml 파일 내부를 보면

답변

0

당신이 체크 박스 ID가 @android:id/text1

0

것을 볼 수 짧은 대답은 그 SimpleCursorAdapter 것이다 원하는 작업하지로 충분.

public void bindView(View view, Context context, Cursor cursor) 방법 (마법이 발생하고보기가 원하는 데이터에 연결되어있는 곳)을 보면 SimpleCursorAdapter이 어떻게 작동하는지 확인할 수 있으며 로직에는 유스 케이스가 없습니다 CheckedTextView

을 바인딩 당신은 Google's code 여기에서 직접 볼 수 CheckedTextView는 텍스트 뷰를 확장하기 때문에 당신이 IllegalStateException이 점점되지 않습니다

if (v instanceof TextView) { 
    setViewText((TextView) v, text); 
} 
else if (v instanceof ImageView) { 
      setViewImage((ImageView) v, text); 
    } 
else { 
     throw new IllegalStateException(v.getClass().getName() + " is not a " + 
           " view that can be bounds by this SimpleCursorAdapter"); 
        } 

유일한 이유입니다.

관련 문제