- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在 ListView 上方有一个 CheckBox,其中包含 Checkbox 项。因此,当我检查复选框时,我应用 notifyDataSetChanged()
来检查列表中的所有项目。所以当时我两次获取 getView 方法的日志,这意味着当我只调用一次 notifyDataSetChanged()
时,getView 被调用了两次。那么,谁能告诉我为什么我会收到两次日志?还有为什么 getView() 被调用了两次?
主类 -
checkAll = (CheckBox) findViewById(R.id.my_check_box);
checkAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton checkbox, boolean arg1) {
adapter.notifyDataSetChanged();
}
});
适配器类代码 -
public class myAdapter extends ArrayAdapter<Model> {
private final List<Model> list;
private final Activity context;
private CheckBox checkAll;
public myAdapter(Activity context, List<Model> list, CheckBox checkAll) {
super(context, R.layout.row, list);
this.context = context;
this.list = list;
this.checkAll = checkAll;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Model element = (Model) viewHolder.checkbox.getTag();
element.setSelected(buttonView.isChecked());
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
if(checkAll.isChecked() == true){
System.out.println(position+" checked th position");
}
else if(checkAll.isChecked() == false){
System.out.println(position+" not checked th position");
}
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
当我可以 adapter.notifyDataSetChanged();
在 CheckAll 复选框上检查 Change Listener 时,LogCat 输出。
11-30 20:31:33.751: INFO/System.out(1300): 0 checked th position
11-30 20:31:33.761: INFO/System.out(1300): 1 checked th position
11-30 20:31:33.770: INFO/System.out(1300): 2 checked th position
11-30 20:31:33.780: INFO/System.out(1300): 3 checked th position
11-30 20:31:33.810: INFO/System.out(1300): 4 checked th position
11-30 20:31:33.810: INFO/System.out(1300): 0 checked th position
11-30 20:31:33.831: INFO/System.out(1300): 1 checked th position
11-30 20:31:33.831: INFO/System.out(1300): 2 checked th position
11-30 20:31:33.851: INFO/System.out(1300): 3 checked th position
11-30 20:31:33.860: INFO/System.out(1300): 4 checked th position
您可以看到我的 Logcat 输出两次得到相同的输出。那么谁能说出为什么会这样?
最佳答案
尝试使您的 ListView
高度为 fill_parent
。
Lisiview 尝试自己根据提供的空间进行一些调整,这是我学到的,看起来这就是背后的原因。
看看是否有帮助。
关于android - 带有 CheckBox 的 ListView 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8340401/
在检查复选框时我发现有写 CheckBox checkbox = (CheckBox)sender 在 checkBox1_CheckedChanged 事件上。 请解释一下这是什么意思? 最佳答案
我正在使用来自命名空间 System.Windows.Forms 的 ToolTip 类编辑我的 Web 应用程序;我的代码中有几个复选框,因此显示此错误: 'CheckBox' is an ambi
我正在制作 Bootstrap 复选框下拉菜单,选项包含在 中。处理点击的标签,但我也有一个 在 a 标签内。 当用户按下实际复选框而不是仅按下 时,就会出现我的问题。元素。两者都被点击并且发生了
TLDR:使用defaultChecked而不是checked,工作jsbin . 尝试设置一个简单的复选框,在选中时会划掉其标签文本。由于某种原因,当我使用该组件时,handleChange 没有被
我想拥有它,所以如果复选框为 NULL 或 0,则它不像值为 1 时那样喜欢。另外,有没有办法将选中的框限制为 10 个? 当前代码: if(isset($_POST['submit'])){//to
如果我选中一个复选框,下拉列表应该只显示在该复选框旁边,但它会显示在它下面的所有其他复选框中。 这是我在 html 代码中使用的 css .sub-nav { display: none; } inp
我在警报对话框中有一个带有复选框的数据表,当我单击该复选框时,它没有选中(选中=选中)该框。我跟着这个video 这是我的尝试 import 'package:flutter/material.dar
如果单独使用,以下代码效果很好, Angular6.0 不允许 [(ngModel)] 与 FormGroup (Reactive Forms)。 As 在 angular 6.0 中已弃用,并将在
那么我应该使用哪个来选择元素?我仅使用复选框作为示例,这个问题涉及所有表单元素。 实际上,当我们这样做时,哪个更快: li:first 或 li:eq(0) ? 最佳答案 来自the document
问题 : 我有一个列表框,其中列表框是复选框。在第一次单击时,复选框被选中并选中。在第二次单击时,仅设置复选框。可以使用箭头键重新选择不同的复选框。我的目标是,首先选中该复选框,然后再检查(再次单击它
我似乎无法弄清楚如何让复选框和相关文本出现在一行上。文本很短,所以它似乎不是宽度问题。 我尝试在控件上设置 display:inline,但是当它呈现时,在输入和标签周围添加了一个跨度,并且具有 di
创建带有复选框列的 Table 非常容易,例如,使用 SWT.CHECK 标志。但是如何使某些表格行中的复选框不可编辑而其他行中的复选框保持可编辑? 最佳答案 我不知道这样做的简单方法。 但我看到了两
是否可以使用 TogglerBar 而不是 2 个复选框来显示或不显示不同的形状。 TogglerBar 的每个按钮中都写有绿色和红色? Manipulate[ Graphics[{If[thePin
我需要更改 Windows Phone 8 中 LongListMultiSelector 的复选框的颜色,因为我的背景是白色,这可能吗? 谢谢。 最佳答案 为此,您必须首先通过在 visual st
我有一个带有插件 Slick.CheckboxSelectColumn 的网格。 是否可以在没有 Jquery 的情况下隐藏某些行中的复选框?我想可以使用 Formatter。 这是带有 slickg
所以我有这个... 在这里,id 是有道理的值在引号中,因为它是一个字符串标识符。但是type呢?值(value)?不是 checkbox一种类型,例如 String 和 Boolean?为什么我总
问题: 如果用户选中了复选框,我将尝试验证下拉列表,如您在屏幕一中所见。 问题: 那么,如果用户选择了标题中的所有复选框,我该如何验证复选框呢?如您所见,屏幕二。如果我选中所有复选框,那么我希望启动验
我知道它有点重复,我正在尝试以不同的方式做到这一点,从而重新发布这个问题。 我想要实现的是,当有人“取消选中”OSPF 复选框时..被动接口(interface)检查也应该自动“取消选中”。我正在尝试
这是代码(是的,我使用的是基本的 reset.css): .checkbox { border: 1px solid black; width: 10px; height: 10px; }
我正在尝试显示多组带有标题复选框的复选框,如下图所示。 从数据库中我得到这样的数据, CODE SUBCODE DESCR DESCR
我是一名优秀的程序员,十分优秀!