1.
view = LayoutInflater.from(this).inflate(R.layout.linkmanview_item, null);
与
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.attachment_item, null);
有什么区别
效率相同吗?2.
listView.getCheckedItemPositions();
返回的SparseBooleanArray怎么用?
怎么用它来判断的点了哪项3.
"如果有固定的ID,也可以使用方法listView.getCheckedItemIds()来得到被选择的 id。"
怎么给项固定ID?
view = LayoutInflater.from(this).inflate(R.layout.linkmanview_item, null);
与
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.attachment_item, null);
有什么区别
效率相同吗?2.
listView.getCheckedItemPositions();
返回的SparseBooleanArray怎么用?
怎么用它来判断的点了哪项3.
"如果有固定的ID,也可以使用方法listView.getCheckedItemIds()来得到被选择的 id。"
怎么给项固定ID?
2、SparseBooleanArray 是一个封装好的数据存储类 把一系列布尔存整型 更有效率
3、没用过,等有空看看
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}这是LayoutInflater.from(this)的具体实现代码,楼主一看便明白是啷个回事喽
2、SparseBooleanArray
SparseBooleanArrays map integers to booleans. Unlike a normal array of booleans there can be gaps in the indices. It is intended to be more efficient than using a HashMap to map Integers to Booleans.
API文档的解释:SparseBooleanArrays 将整型数据映射为boolean.不像一般的boolean类型的数组可以在索引值之间有间隙.这个比直接使用HashMap映射boolean值效率更高些.3、建议楼主研究一下多选列表这块的代码,getCheckItemIds () 从字面意思理解应该是跟CheckBox有关的
关于第二点的问题
一共有5项不管单独点击那一项返回的都是一个false
我怎么知道用户点击了哪一项
问题2
SparseBooleanArray
SparseBooleanArrays map integers to booleans. Unlike a normal array of booleans there can be gaps in the indices. It is intended to be more efficient than using a HashMap to map Integers to Booleans.
API文档的解释:SparseBooleanArrays 将整型数据映射为boolean.不像一般的boolean类型的数组可以在索引值之间有间隙.这个比直接使用HashMap映射boolean值效率更高些.楼主可以直接理解为一个map,我通过对这个类的源码进行了查看发现里面有三个属性:mKeys(整型数组),mValues(boolean数组),mSize(int),其中的put、get、append方法的思想与map十分类似,可以认为SparseBooleanArray是一个只用来映射boolean类型数据的轻量级map问题3
getCheckedItemIds()
先来一段该方法的注释:
Returns the set of checked items ids. The result is only valid if the choice mode has not been set to CHOICE_MODE_NONE and the adapter has stable IDs. (hasStableIds() == true)Returns
A new array which contains the id of each checked item in the list. 翻译过来便是:
返回已经被check的选项的id号的集合.这个返回结果只有在choice mode没有被设置成为CHOICE_MODE_NONE并且adapter拥有稳定的IDs(即 hasStableIds() == true).这就说明了getCheckedItemIds()方法应该是只能在多选模式下有用了。
看看getCheckedItemIds()方法的返回值,一个包含被check的item的list集合的数组。通过对注释的理解,我认为这个东西是当ListView在多选模式下的时候,当你勾选了几个复选框之后那么getCheckedItemIds()方法返回的就是那些被选中的复选框的id的数组。
关于如何给固定值这个我觉得应该是有AbsListView或者adapter这种东西自行决定的吧