- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我的 ListView 有我自己的布局和 CustomCursorAdapter。每行都有自己的复选框。所以......绝对清楚,在滚动期间,复选框会失去它们的状态。我找到的唯一东西是Android save Checkbox State in ListView with Cursor Adapter但那里没有答案。还有一个问题。我的CustorArrayAdapter 也有同样的问题。我使用 SparseBooleanArray 解决了这个问题,以保持复选框状态。它工作正常,但每次滚动都会调用 onCheckedChanged。这正常吗?这笔交易是我的 ListView 描述了警报元素和定期调用(onCheckedChanged)启动/停止警报。很多不必要的操作。
最佳答案
我的 ListView
与 CheckBox
有类似的问题,我做了什么来解决这个问题:
false
,表示还没有选中CheckBox。public class MyDataAdapter extends SimpleCursorAdapter {
private Cursor c;
private Context context;
private ArrayList<String> list = new ArrayList<String>();
private ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
// itemChecked will store the position of the checked items.
public MyDataAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
for (int i = 0; i < this.getCount(); i++) {
itemChecked.add(i, false); // initializes all items value with false
}
}
public View getView(final int pos, View inView, ViewGroup parent) {
if (inView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inView = inflater.inflate(R.layout.your_layout_file, null);
}
final CheckBox cBox = (CheckBox) inView.findViewById(R.id.bcheck); // your
// CheckBox
cBox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v.findViewById(R.id.your_checkbox_id);
if (cb.isChecked()) {
itemChecked.set(pos, true);
// do some operations here
} else if (!cb.isChecked()) {
itemChecked.set(pos, false);
// do some operations here
}
}
});
cBox.setChecked(itemChecked.get(pos)); // this will Check or Uncheck the
// CheckBox in ListView
// according to their original
// position and CheckBox never
// loss his State when you
// Scroll the List Items.
return inView;
}}
关于Android:CursorAdapter、ListView 和 CheckBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4803756/
在我的应用程序中,我显示一些信息,并根据值更改 textView 的颜色。 public class DealsAdapter extends CursorAdapter { private
我正在尝试获取使用自定义 CursorAdapter 存储的数据,但到目前为止它默默地失败了。它只是加载一个空白 View 并且不打印任何内容。 这是主 fragment 的 onCreateView
好吧,因为我在搜索时没有找到执行此操作的一致方法,所以我决定将我的代码放在其他人的眼睛上可能会有所帮助。 我正在制作一款使用纸牌的游戏。根据不同的因素,这些卡可以被锁定或解锁。重要的是,我想检查 sq
我有一个 ChatActivity,它通过 CursorLoader 加载它的数据。 CursorLoader 返回一个带有两个寄存器的游标,但永远不会调用适配器中的 newView 和 bindVi
我不确定问题标题是否合适,但是在搜索了很多之后我问了这个。 在我的 SQLite 表中,我有列 1: _id 2: position 3: path position: the positio
SearchView 的方法 setSuggestionsAdapter 给我一个奇怪的错误: 我有一个扩展 CursorAdapter 的类 InformationAdapter,但它告诉我我不能将
我最近写了一个 StackOverflow 文档示例,说明了如何使用 SimpleCursorAdapter 从数据库中填充 ListView。 它被拒绝了,动机如下: Nobody should b
我正在制作一个 StudentManager 应用程序。 在MainActivity.java中,当我触摸 float 按钮时,它将切换到EditActivity.java。然后,在 EditActi
我读了这个post 但我无法解决我的问题。我在 ListView 中使用 CursorAdapter。 我在列表的每个项目中都有一个复选框。如果您选中该复选框并上下滚动。该复选框将被禁用。我无法修复它
我目前使用 CursorAdapter 和 Loader。 Loader 加载的数据包含一个位置。我想从最近到最远的顺序订购我的商品。我已经计算出显示它的距离,现在我需要找到一种方法对数据进行动态排序
CursorAdapter 有 3 个构造函数。让我们看看指南和引用。 1) CursorAdapter(Context context, Cursor c) This constructor is
我有一个 ListFragment,它显示使用 CursorLoader 和 CursorAdapter 获得的项目列表,按照处理列出。这本身工作正常,但我不确定如何使用相同的模式来显示所选项目的详细
我有一个 CursorAdapter,它是从数据库 Cursor 构建的,如果第一个项目中的 View 没有填写,它使用设置了 View 的第一个后续列表项中的 View 中出现的任何数据填充第一个项
我有一个数据库、一个 ListView 和一个扩展 CursorAdapter 的 CustomCursorAdapter。一个菜单按钮将一个项目添加到数据库中。我希望 ListView 更新并显示此
我有一个可以帮助用户组织处方的应用程序。我有一个显示药物的 ListView ,我使用 EditText 来允许用户过滤列表。我遇到的问题是每次方向改变时 CursorLoader 都会被替换。 据我
在 Ice Cream Sandwich 上,当我想恢复具有带 CursorAdapter 的 gridview 且已将 managedQuery 传递给 CursorAdapter 的应用程序时,我
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
您好,我正在开发一个带有 CursorAdapter 的 Android 应用程序来加载 ListView 。 onItemClick ListView 项目,我正在尝试开始对话 Activity 。
我正在使用 SimpleCursorAdapter 来管理我对数据库的查询,然后在 ListView 中显示结果。 这是我的代码: database.open(); ListView listCont
我正在尝试用数据库查询填充 ListView 。我正在使用扩展游标适配器的自定义适配器。我不知道要使用什么构造函数。当我使用默认的时: public AdapterListview(Context c
我是一名优秀的程序员,十分优秀!