2010-02-28 55 views
0

我有一个包含5个TabHost.TabSpec的TabHost。每个TabSpec是使用SimpleCursorAdapter填充的ListView,其中数据源是sqlite3数据库。Android:TabHost ListView的CheckBox的

SimpleCursorAdapter使用的布局包含2个保存数据库数据的TextView(一个隐藏 - 其中包含数据库记录_id,另一个隐藏)。第三个小部件是CheckBox。见下面的布局:

<RelativeLayout 
    android:id="@+id/favoriteRow" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<TextView 
    android:id="@+id/text0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:visibility="gone" 
    android:paddingLeft="5px"> 
</TextView> 
<TextView 
    android:id="@+id/text1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/text0" 
    android:textColor="@color/listTextColor" 
    android:textSize="@dimen/font_size_for_show_row" 
    android:paddingTop="@dimen/vertical_padding_for_show_row" 
    android:paddingBottom="@dimen/vertical_padding_for_show_row"> 
</TextView> 
<com.example.subclass.FavoriteCheckBox 
    android:text="" 
    android:id="@+id/favorite_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:checked="false"> 
</com.example.subclass.FavoriteCheckBox> 
</RelativeLayout> 

我的主要问题是我不知道如何捕获/侦听当用户点击CheckBox。我使用FavoriteCheckBox对CheckBox进行了分类,并添加了protected void onClick(View v),但当我单击复选框时,我从未到达此位置。

任何关于我失踪的建议。

TIA,

JB

回答

0

你会只需要一个侦听器添加到您在代码中创建实例:

CheckBox repeatChkBx = 
    (CheckBox) findViewById(R.id.favorite_checkbox); 
repeatChkBx.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{ 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
    { 
     if (isChecked) 
     { 
      // perform logic 
     } 

    } 
}); 

途经:http://mgmblog.com/2008/02/18/android-checkbox-oncheckedchangelistener/

相关问题