嗨,我设置了 CheckedTextView,但我无法让 onClick 事件正常运行。我将 onClick 代码放在 main.layout 的 onCreate 中,但我在第 101 行得到一个空指针,即 chkBox.setOnClickListener(new View.OnClickListener()。Listview 是在 AsyncTask 的 onPostExecute 中创建的。有人可以帮忙吗?
我的 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=""
/>
我的点击事件:
CheckedTextView chkBox = (CheckedTextView) findViewById(R.id.listCheckboxview);
chkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
((CheckedTextView) v).toggle();
}
});