如何通过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 (将#修改为@)