Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何访问“回收器”视图中屏幕上尚未显示的复选框_Android_Checkbox_Android Recyclerview - Fatal编程技术网

Android 如何访问“回收器”视图中屏幕上尚未显示的复选框

Android 如何访问“回收器”视图中屏幕上尚未显示的复选框,android,checkbox,android-recyclerview,Android,Checkbox,Android Recyclerview,我刚接触安卓系统,在学习的过程中我学到了很多东西。因此,这个查询可能非常基本 我正在通过RecycleServiceAdapter显示复选框列表。某些复选框用于选择整个复选框组。我想做的是,如果选中其中一个组复选框,我想选中该组中的所有复选框 在我选中已经可见的复选框之前,一切都很正常,但是当迭代器超出可见的范围时,我会得到一个空返回 我已经使用FindViewHolder进行了自适应和getChildAt。两者都有相同的问题。我是否可以访问屏幕上尚未显示的框 onCheckedChangedL

我刚接触安卓系统,在学习的过程中我学到了很多东西。因此,这个查询可能非常基本

我正在通过RecycleServiceAdapter显示复选框列表。某些复选框用于选择整个复选框组。我想做的是,如果选中其中一个组复选框,我想选中该组中的所有复选框

在我选中已经可见的复选框之前,一切都很正常,但是当迭代器超出可见的范围时,我会得到一个空返回

我已经使用FindViewHolder进行了自适应和getChildAt。两者都有相同的问题。我是否可以访问屏幕上尚未显示的框

onCheckedChangedListener的相关部分如下所示

    private CompoundButton.OnCheckedChangeListener checkChangedListener = new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        final HeaderListStructure structure = (HeaderListStructure) buttonView.getTag();
        if (isChecked) {
            if (structure != null) {
                selectedRules.add(structure);
                if (structure.type != Constants.TYPE_ITEM){
                    ArrayList<Object> temp = (ArrayList) structure.additionalInfo;
                    for (Object obj : temp){
                        int itr = (int) obj;
                        Log.d(TAG, "onCheckedChanged: Print out int" + itr);
                        RecyclerView checkbox = (RecyclerView) buttonView.getParent().getParent();

                        LinearLayout linearLay = (LinearLayout) checkbox.findViewHolderForAdapterPosition(itr).itemView;
                        CompoundButton buttonToSet= (CompoundButton) linearLay.getChildAt(0);
                        buttonToSet.setChecked(true);

                    }
                }
            }
        } else {

刚刚想出了一个办法来处理这种情况。共享它,以防将来其他人有类似的查询

对于尚未可见的视图,我只是在适配器使用的数组中标记了它们。数组的每个元素都有一个名称和类型。使用类型存储复选框的状态,每次“回收器”视图创建该视图时,状态都与类型中存储的值一致


谢谢

为什么不在屏幕上使用recyclerview将这些“不可访问”复选框放置在可见性
消失的情况下
。Piotrek说,“消失”意味着它不会占用任何空间,但它可以让你检查你是否已经检查了答案。我该怎么做?我很抱歉,但正如我所说的,我边走边学。以及如何在用户滚动时使它们再次可见?将
setVisibility(View.GONE)
属性添加到将要加载的复选框中,但此时不希望使它们可见。要使它们可见,可以使用
setVisibility(View.visible)
是的,但我如何知道何时将它们设置为可见。我已经编辑了这个问题,添加了onCreate和OnbindviewHolder的代码。我应该对此进行哪些编辑?再次谢谢
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_add_mode_smart_rule, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final HeaderListStructure structure = rulesListing.get(position);
    if (structure.type  == Constants.TYPE_ITEM) {
        holder.itemView.setPadding(80, 20, 20, 20);
        holder.itemView.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= 23) {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.white, null));
        } else {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.white));
        }
    }else if(structure.type==Constants.TYPE_SUBHEADER2){
        holder.itemView.setPadding(60, 20, 20, 20);
        holder.itemView.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= 23) {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.background_color, null));
        } else {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.background_color));
        }

    } else if(structure.type==Constants.TYPE_SUBHEADER) {
        holder.itemView.setPadding(40, 20, 20, 20);
        holder.itemView.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= 23) {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.light_cyan, null));
        } else {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.light_cyan));
        }

    } else {
        holder.itemView.setPadding(20, 20, 20, 20);
        holder.itemView.setVisibility(View.VISIBLE);
        if (Build.VERSION.SDK_INT >= 23) {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.light_pink, null));
        } else {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.light_pink));
        }
    }

    final String rule = structure.name;
    holder.cbRule.setText(rule);
    holder.cbRule.setTag(structure);
    holder.cbRule.setVisibility(View.VISIBLE);
    holder.cbRule.setOnCheckedChangeListener(checkChangedListener);
}