2011-03-24 6 views
0

[안드로이드] 내가 목록보기 확인란에 alistener을 만들고 싶어 하지만 난 (체크 박스 ID가 row.xml 레이아웃에 정의)체크 박스의 청취자 문제

+1

코드 붙여 넣기 ... 디버그하기가 쉽습니다 .. – Venky

+0

CheckBoxById (...)를 사용하여 CheckBox를 얻지는 않았지만 예 - 소스 코드를 사용하는 것처럼 들립니다. – Klaus

답변

0

난 체크 박스의 청취자를 쓴 줄에서 널 포인터 예외를 가지고

mContactList.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      Log.i("onClick", "sur un Item"); 
      LinearLayout linear = (LinearLayout) view; 
      CheckBox registeredBox = (CheckBox) linear 
        .findViewById(R.id.registered_checkbox); 
      if (registeredBox.isChecked()) // your code 

     } 
}); 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_height="wrap_content" android:baselineAligned="false" android:layout_width="fill_parent"> 
     <TableRow android:id="@+id/tableRow2" android:layout_height="fill_parent" android:layout_width="fill_parent" android:gravity="left|right" android:padding="5px"> 
      <LinearLayout android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_height="wrap_content" android:minHeight="25px" android:layout_width="wrap_content"> 
       <TextView android:layout_height="wrap_content" android:id="@+id/ContactName" android:textSize="18px" android:text="@+id/ContactName" android:layout_width="fill_parent"></TextView> 
       <TextView android:layout_height="wrap_content" android:id="@+id/ContactStatus" android:textSize="12px" android:scrollHorizontally="true" android:textStyle="italic" android:layout_width="fill_parent" android:text="Ceci est mon statut"></TextView> 
      </LinearLayout> 
     <TableRow android:layout_height="fill_parent" android:id="@+id/indicator_logo_table" android:visibility="visible" android:layout_width="fill_parent" android:minHeight="25px" android:gravity="right"> 
      <CheckBox android:checked="false" android:text="CheckBox" android:id="@+id/registered_checkbox" android:visibility="invisible" android:layout_height="1dip" android:layout_width="1dip"></CheckBox> 
      <ImageView android:id="@+id/wish_button" android:paddingLeft="5px" android:paddingRight="5px" android:src="@drawable/wishbutton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="right" android:clickable="true"></ImageView> 
     </TableRow> 
    </TableRow> 
</LinearLayout> 

그것이 도움이되기를 바랍니다

처럼 내을 listitem 레이아웃은 같습니다 하나 개의 샘플이 실행되고!

+0

감사합니다 예외가 제거됩니다하지만 확인란을 클릭 할 때 나는 단지 목록 항목을 클릭 할 때 someting 할 거 야 확인란을 이벤트를 만들고 싶어? – user651280

관련 문제