Hi i setup a CheckedTextView but I can't get the onClick event functioning. I put the onClick code in the onCreate of the main.layout but I get a nullpointer at line 101, which is chkBox.setOnClickListener(new View.OnClickListener(). The Listview is created in the onPostExecute of a AsyncTask. Can someone please help?
My CheckedTextView:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listCheckboxview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" android:gravity="left"
android:textColor="#0075AB" android:textStyle="bold" android:textSize="14dip"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:clickable="true"
android:focusable="true"
android:text=""
/>
My onClick event:
CheckedTextView chkBox = (CheckedTextView) findViewById(R.id.listCheckboxview);
chkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
((CheckedTextView) v).toggle();
}
});
This means that
chkBox
isnull
, which means that Android is not findingR.id.listCheckboxview
. Make sure you are callingfindViewById()
on the right thing (here, you appear to be calling it on the activity, but your question mentions aListView
). Also, try cleaning your project (Project > Clean from the Eclipse main menu, orant clean
from the command line), as sometimes theR
constants get out of sync.