[英]Checkbox state problem in ListView
Hello with regard to the known issue of unwanted checkboxes being checked while scrolling through a listview, can anyone please give me an idea how to use a checkedTextView properly so that i can maintain check state properly when scrolling through the list. 您好,关于在滚动列表视图时选中不需要复选框的已知问题,任何人都可以给我一个想法,如何正确使用checkedTextView,以便在滚动列表时可以正确地保持选中状态。 I thought the listview takes care of maintaining the checkbox state when using a checkedtextView but that does not seem to be the case.
我以为listview在使用checkedtextView时会注意保持复选框状态,但事实并非如此。 or do i have to use the default Id for the checkedTextView.
还是我必须对checkedTextView使用默认的ID。 I can't seem to find an example that uses a cursorAdapter or a SimpleCursorAdapter for this case.
我似乎找不到这种情况下使用cursorAdapter或SimpleCursorAdapter的示例。 Thank you
谢谢
i have tried using this, but am not really sure what to do with the set tag position. 我已经尝试过使用此功能,但不确定如何处理设置的标签位置。 here is a small piece of code:
这是一小段代码:
//bindView() method in SimpleCursorAdapter
//viewHolder holder;
//Cursor c;
holder.checkedText = (CheckedTextView)view.findViewById(R.id.view_checked);
holder.checkedText.setTag(c.getPosition());
holder.checkedText.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
v.getTag();
((CheckedTextView) v).toggle();
}
});
my xml standard layout: 我的xml标准布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="multipleChoice"/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_notes"/>
</LinearLayout>
my custom layout: 我的自定义布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="6dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/viewNameText"
android:id="@+id/viewNameId">
</TextView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start Date"
android:layout_gravity="right"
android:id="@+id/DateId">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="start Time"
android:layout_gravity="right"
android:id="@+id/TimeId">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
>
<CheckedTextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="false"
android:focusable="false"
android:clickable="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
/>
</LinearLayout>
</LinearLayout>
I thought the listview takes care of maintaining the checkbox state when using a checkedtextView but that does not seem to be the case.
我以为listview在使用checkedtextView时会注意保持复选框状态,但事实并非如此。
It should, if your ListView
is android:choiceMode="multiple"
. 如果您的
ListView
是android:choiceMode="multiple"
,则应该这样。
do i have to use the default Id for the checkedTextView
我是否必须为checkedTextView使用默认ID?
You might. 你可能会的。 The only times I have implemented a multiple choice
ListView
, I have used the standard row layout rather than a custom one. 我仅有一次实现了多项选择
ListView
,而是使用了标准的行布局,而不是自定义的行布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.