2010-02-28 54 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/

相關問題