我正在开发使用安卓
应用程序的ListView
。
I'm developing a Android
application using ListView
.
的ListView
在每一个文件列表项
。在这里,我在的ListView
设置 onItemClick
。因此,如果用户点击了列表项
电子邮件应用程序被打开并附加特定的文件中的电子邮件。它为单文件
,这得到落实,工作正常。
ListView
have a one file in each and every ListItem
. Here, I have set onItemClick
in ListView
. So, that if user clicks the ListItem
email application gets open and attach the particular file in email. Its for the single File
, this gets implemented and working fine.
现在我要附加多个文件的电子邮件。即实施复选框
中的每个列表项
和检查的项目必须附加到邮件。
Now I want attach the multiple file in email. i.e. the implementing the CheckBox
in each ListItem
and checked items have to attached into the Mail.
我知道它,因为它可能非常相似,检查多个文件,并通过单击单个按钮
删除所有文件中的文件管理器应用程序。但不知道该怎么办。
I know its possible because its very similar to the file manager application that checking the multiple file and deleting the all file by clicking the single Button
. But don't know how to do.
推荐答案
在你ListAdapter创建SparseBooleanArray
In you ListAdapter create a SparseBooleanArray
private SparseBooleanArray checkStatus;
这SparseBooleanArray存储检查的项目。现在,在getView做以下
This SparseBooleanArray stores the checked items. Now in getView do the following
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewCache viewCache;
if (view == null){
viewCache = new ViewCache();
view = layoutInflater.inflate(R.layout.list_box, null, false);
viewCache.checkBox = view.findViewById(R.id.check_box);
viewCache.checkBox.setOnCheckedChangeListener(onCheckedChangeListener);
//other views in the list box
...........
}
vewCache = (ViewCache)view.getTag();
viewCache.checkBox.setTag(position);
viewCache.checkBox.setChecked(isChecked(position));
//set other views
........
}
这是类视图缓冲
private static class ViewCache{
CheckBox checkBox;
//other views in the list box
.......
}
此方法检查位置是否检查
This method checks whether the position is checked
private boolean isChecked(int position){
return checkStatus.get(position, false);
}
这是onCheckChangeListener
This is the onCheckChangeListener
CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
checkStatus.put(((Integer)compoundButton.getTag()), b);
}
};
最后,你可以从SparseBooleanArray的checkStatus的检查项目。认为这将帮助你。
Finally you can get the checked items from the SparseBooleanArray checkStatus. Think it will help you.
相关推荐
最新文章