Listview Android:TabHost,列表视图为CheckBox';
我有一个包含5个TabHost.TabSpec的TabHost。每个TabSpec都是一个ListView,使用SimpleCursorAdapter填充,数据源是一个sqlite3数据库 SimpleCursorAdapter使用的布局包含2个文本视图,其中包含数据库数据(一个隐藏-包含数据库记录id,另一个显示)。第三个小部件是一个复选框。见下面的布局图:Listview Android:TabHost,列表视图为CheckBox';,listview,android,checkbox,android-tabhost,Listview,Android,Checkbox,Android Tabhost,我有一个包含5个TabHost.TabSpec的TabHost。每个TabSpec都是一个ListView,使用SimpleCursorAdapter填充,数据源是一个sqlite3数据库 SimpleCursorAdapter使用的布局包含2个文本视图,其中包含数据库数据(一个隐藏-包含数据库记录id,另一个显示)。第三个小部件是一个复选框。见下面的布局图: <RelativeLayout android:id="@+id/favoriteRow" android:layou
<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>
我的主要问题是,当用户“单击”复选框时,我不知道如何捕获/侦听。我用FavoriteCheckBox
对复选框进行了子类化,并在单击(视图v)时添加了一个受保护的void,但当我单击复选框时,我从未到达那里
任何关于我遗漏什么的建议
蒂亚
jb您只需在代码中创建的实例中添加一个侦听器:
CheckBox repeatChkBx =
( CheckBox ) findViewById( R.id.favorite_checkbox );
repeatChkBx.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if ( isChecked )
{
// perform logic
}
}
});
通过: