如何解决如何通过ListView / GridView识字每个列表项并检查复选框是否被选中-Android Java
大家好,我想检查我的GridView并查看是否选中了任何复选框。最终,我想删除数据库中的行并更新我的自定义适配器,但是我对使用什么功能或如何使用它感到迷茫。我知道使用某种while / for循环,但是哪种数据类型可以浏览和迭代每个列表项?我环顾四周,.getChildAt(index)似乎很有用,但对于我的MainActivity中的自定义适配器变量而言,它不起作用/不显示。
这是我的自定义适配器类供参考
//variable responsible for making checkbox visible or not
private boolean displayCheckBox;
//constructor - it takes the context and the list of words
WordAdapter(Context context,ArrayList<WordFolder> word){
super(context,word);
}
//sets the visibility of the checkBox
public void setCheckBoxVisibility(boolean visible){
this.displayCheckBox = visible;
}
@Override
public View getView(int position,View convertView,ViewGroup parent){
View listItemView = convertView;
if(listItemView == null){
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.folder_view,parent,false);
}
//getting the checkBox view id
CheckBox checkBox = (CheckBox) listItemView.findViewById(R.id.check_box);
checkBox.setVisibility(displayCheckBox ? View.VISIBLE : View.GONE);
//Getting the current word
WordFolder currentWord = getItem(position);
//making the 3 text view to match our word_folder.xml
TextView date_created = (TextView) listItemView.findViewById(R.id.date_created);
TextView title = (TextView) listItemView.findViewById(R.id.title);
TextView desc = (TextView) listItemView.findViewById(R.id.desc);
//using the setText to get the text and set it in the textView
date_created.setText(currentWord.getDateCreated());
title.setText(currentWord.getTitle());
desc.setText(currentWord.getTitleDesc());
return listItemView;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。