简体   繁体   English

如何在bottomSheet中检查recyclerview项目并通过bottomSheet中的按钮传递多个检查数据

[英]How can I get checked recyclerview item in bottomSheet And Pass multiple Checked data by button in bottomSheet

Hi I don't know how to upload multiple checked recyclerview item data to firebase.嗨,我不知道如何将多个已检查的 recyclerview 项目数据上传到 firebase。

So I think I have to know which recyclerview item is checked for uploading data to firebase.所以我想我必须知道要检查哪个recyclerview项目才能将数据上传到firebase。

But In bottomsheet java file, I don't know How can I get which one is checked.但是在底页 java 文件中,我不知道如何检查哪一个。

My scenarios is that, If user check items'checkbox (multiple item check is available) and click done button, Uploading data to firebase.我的场景是,如果用户选中项目的复选框(可以进行多项检查)并单击完成按钮,则将数据上传到 firebase。

How can I solve it?我该如何解决?

It's my Adapter for recyclerview in bottomsheet这是我在底页中用于 recyclerview 的适配器

public class AdapterPinBottomSheet extends RecyclerView.Adapter<AdapterPinBottomSheet.ViewHolder> {

ArrayList<ItemBottomSheetFolderList> array;
Context context;
private RecyclerViewClickListener listener;

public AdapterPinBottomSheet(ArrayList<ItemBottomSheetFolderList> array, Context context, RecyclerViewClickListener listener) {
    this.array = array;
    this.context =context;
    this.listener = listener;
}

@NonNull
@Override
public AdapterPinBottomSheet.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_folderlist_bottomsheet,parent,false);
    return new AdapterPinBottomSheet.ViewHolder(view);
}

@SuppressLint("ResourceAsColor")
@Override
public void onBindViewHolder(@NonNull AdapterPinBottomSheet.ViewHolder holder, int position) {
    final ItemBottomSheetFolderList itemBottomSheetFolderList = array.get(position);
    holder.listFolderName.setText(array.get(position).getFolderName());
    holder.listFolderPinNum.setText(String.valueOf(array.get(position).getFolderPinNum()));
    holder.cbPinFolder.setOnCheckedChangeListener(null);

    holder.cbPinFolder.setChecked(itemBottomSheetFolderList.isSelected());

    holder.cbPinFolder.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            itemBottomSheetFolderList.setSelected(isChecked);
        }
    });

}
@Override
public int getItemCount() {
    return array.size();
}

public interface RecyclerViewClickListener{
    void onClick(View v, int position);
}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    TextView listFolderName;
    TextView listFolderPinNum;
    CheckBox cbPinFolder;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        listFolderName =itemView.findViewById(R.id.listFolderName);
        listFolderPinNum =itemView.findViewById(R.id.listFolderPinNum);
        cbPinFolder =itemView.findViewById(R.id.cbPinFolder);
        itemView.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        listener.onClick(itemView, getAdapterPosition());
        cbPinFolder.performClick();
    }
}

}

And This code(in dialog file) is related to recyclerview.并且此代码(在对话框文件中)与 recyclerview 有关。

public interface BottomSheetListener {
    void onButtonClicked(String text);
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    try {
        mListener = (BottomSheetListener) context;
    } catch (ClassCastException e) {
        throw new ClassCastException(context.toString()
                + " must implement BottomSheetListener");
    }
}

private void setFolderOnClickListener(){
    folderListener = new AdapterPinBottomSheet.RecyclerViewClickListener() {
        @Override
        public void onClick(View v, int position) {
            mListener.onButtonClicked("폴더 clicked");
        }
    };
}

For understanding I add my UI为了理解,我添加了我的 UI

在此处输入图像描述

You can create a method in your Adapter which you can call on Done click to get the selected list of data.您可以在适配器中创建一个方法,您可以在完成单击时调用该方法以获取选定的数据列表。 something like below像下面的东西

 public ArrayList<ItemBottomSheetFolderList> getSelectedArray() {
        ArrayList<ItemBottomSheetFolderList> selectedArray = new ArrayList<>();
        for (ItemBottomSheetFolderList folderList : array) {
            if (folderList.isSelected()) {
                selectedArray.add(folderList);
            }
        }
        return selectedArray;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在底页中滚动recyclerview,但底页不能滑动 - how can i scroll recyclerview in bottomsheet,but bottomsheet not to slide 如何将数据从 Activity 传递到 BottomSheet Fragment? - How can I pass data from Activity to BottomSheet Fragment? 如何在底表中包含recyclerview? - How to include recyclerview in bottomsheet? 如何从 RecyclerView 读取数据并发送到 BottomSheet - How to Read Data from RecyclerView and send in BottomSheet 滚动不适用于BottomSheet中的多个RecyclerView - Scroll not working for multiple RecyclerView in BottomSheet 获取BottomSheet的高度,以便recyclerview始终保持在其上方 - Get height of a BottomSheet so that recyclerview can always stay above it 如何设置用Kotlin检查的RecyclerView中的第一个单选按钮? - How can I set the first radio button in RecyclerView checked with Kotlin? 我们如何在 android 的 RecyclerView 片段中使用 bottomSheet? - How we can use bottomSheet in fragment for RecyclerView in android? 如何将 RecyclerView 向前滚动到它的父级(BottomSheet)以折叠它? - How can I forward scrolling the RecyclerView to its parent which is a BottomSheet in order to collapse it? 无法从 RecyclerView 更新 BottomSheet 上的数据 - Not able to update data on BottomSheet from RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM