开发者

checkbox listner problem

[android] i want to make alistener on list view checkbox but i got null pointer exception at the line where i wrote the checkbox listner (chec开发者_如何学Pythonk box id defined at row.xml layout )


i have one sample running :

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

        }
});

and my listitem layout looks like

<?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>

hope it helps !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜