Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.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
复选框选择和取消选择 package com.example.adapter; 导入android.content.Context; 导入android.support.v7.widget.RecyclerView; 导入android.util.Log; 导入android.util.SparseBooleanArray; 导入android.view.LayoutInflater; 导入android.view.view; 导入android.view.ViewGroup; 导入android.widget.CheckBox; 导入android.widget.CompoundButton; 导入android.widget.TextView; 导入android.widget.Toast; 导入com.example.aayushchaubey.meetdax.R; 导入com.google.android.gms.tasks.Task; 导入com.google.firebase.firestore.QuerySnapshot; 导入java.util.ArrayList; 导入java.util.HashMap; 公共类DifferentGenderServicesAdapter2扩展了RecyclerView.Adapter{ 私人任务; 字符串id,servicename; ArrayList serviceArray=新的ArrayList(); ArrayList costArray=新的ArrayList(); ArrayList StyleStidarray=新ArrayList(); ArrayListdurationArray=新的ArrayList(); TextView服务电视、durationTv; 整数计数=0; 字符串strService; ArrayList keyArr=新的ArrayList(); ArrayListserviceDocumentId=新的ArrayList(); ArrayList SelectedServiceId=新的ArrayList(); ArrayList SelectedServiceArray=新建ArrayList(); ArrayList SelectedServiceCost=新建ArrayList(); ArrayListdurationArr=新的ArrayList(); 字符串serviceId、strStylist、strDuration; ArrayList Styleist=新的ArrayList(); ArrayList SelectedStyleStId=新建ArrayList(); 公共差异EnderservicesAdapter2(任务任务、ArrayList id、TextView服务STV、TextView持续时间TV){ this.task=任务; this.serviceTv=servicesTv; this.durationTv=durationTv; this.serviceDocumentId=id; count=task.getResult().size(); } @凌驾 public RecyclerView.ViewHolder onCreateViewHolder(视图组父级,int-viewType){ View=LayoutFlater.from(parent.getContext()).flate(R.layout.services_项,parent,false); 返回新的DifferentGenderServicesAdapter2.listViewHolder(视图); } @凌驾 公共无效onBindViewHolder(最终RecyclerView.ViewHolder,最终整型位置){ 试一试{ ((listViewHolder)holder.servicenameTv.setText(task.getResult().getDocuments().get(position.get(“name”).toString()); ((listViewHolder)holder.serviceCost.setText(task.getResult().getDocuments().get(position.get(“price”).toString()); servicename=task.getResult().getDocuments().get(位置).get(“名称”).toString(); 整数价格=task.getResult().getDocuments().get(position).getLong(“价格”).intValue(); serviceArray.add(servicename); costArray.add(价格); ArrayListStylestarr=新的ArrayList(); Stylestarr=(ArrayList)task.getResult().getDocuments().get(position.get(“服务”); ArrayList StylesId=新的ArrayList(); style.sid.clear(); 对于(int i=0;i1){ 成本=selectedServiceCost.get(0)+selectedServiceCost.get(1); }否则{ 成本=selectedServiceCost.get(0); } 退货成本; } 公共整数getDurationArr(){ 整数持续时间=空; 如果(持续时间arr.size()>1){ duration=durationArr.get(0)+durationArr.get(1); }否则{ duration=durationArr.get(0); } 返回时间; } 公共阵列列表GetSelectedStyleStId(){ 返回所选样式ID; } @凌驾 public int getItemCount(){ 返回计数; } 私有类listViewHolder扩展了RecyclerView.ViewHolder{ 私有复选框; 私有文本视图servicenameTv,serviceCost; 整数计数=0; 字符串strService; 公共列表视图持有者(最终视图项视图){ 超级(项目视图); 试一试{ servicenameTv=(TextView)itemView.findViewById(R.id.damerServiceTV); serviceCost=(TextView)itemView.findViewById(R.id.damerRsTV); checkBox=(checkBox)itemviewbyd(R.id.checkBox); }捕获(例外e){ e、 printStackTrace(); } } } }_Java_Android - Fatal编程技术网

复选框选择和取消选择 package com.example.adapter; 导入android.content.Context; 导入android.support.v7.widget.RecyclerView; 导入android.util.Log; 导入android.util.SparseBooleanArray; 导入android.view.LayoutInflater; 导入android.view.view; 导入android.view.ViewGroup; 导入android.widget.CheckBox; 导入android.widget.CompoundButton; 导入android.widget.TextView; 导入android.widget.Toast; 导入com.example.aayushchaubey.meetdax.R; 导入com.google.android.gms.tasks.Task; 导入com.google.firebase.firestore.QuerySnapshot; 导入java.util.ArrayList; 导入java.util.HashMap; 公共类DifferentGenderServicesAdapter2扩展了RecyclerView.Adapter{ 私人任务; 字符串id,servicename; ArrayList serviceArray=新的ArrayList(); ArrayList costArray=新的ArrayList(); ArrayList StyleStidarray=新ArrayList(); ArrayListdurationArray=新的ArrayList(); TextView服务电视、durationTv; 整数计数=0; 字符串strService; ArrayList keyArr=新的ArrayList(); ArrayListserviceDocumentId=新的ArrayList(); ArrayList SelectedServiceId=新的ArrayList(); ArrayList SelectedServiceArray=新建ArrayList(); ArrayList SelectedServiceCost=新建ArrayList(); ArrayListdurationArr=新的ArrayList(); 字符串serviceId、strStylist、strDuration; ArrayList Styleist=新的ArrayList(); ArrayList SelectedStyleStId=新建ArrayList(); 公共差异EnderservicesAdapter2(任务任务、ArrayList id、TextView服务STV、TextView持续时间TV){ this.task=任务; this.serviceTv=servicesTv; this.durationTv=durationTv; this.serviceDocumentId=id; count=task.getResult().size(); } @凌驾 public RecyclerView.ViewHolder onCreateViewHolder(视图组父级,int-viewType){ View=LayoutFlater.from(parent.getContext()).flate(R.layout.services_项,parent,false); 返回新的DifferentGenderServicesAdapter2.listViewHolder(视图); } @凌驾 公共无效onBindViewHolder(最终RecyclerView.ViewHolder,最终整型位置){ 试一试{ ((listViewHolder)holder.servicenameTv.setText(task.getResult().getDocuments().get(position.get(“name”).toString()); ((listViewHolder)holder.serviceCost.setText(task.getResult().getDocuments().get(position.get(“price”).toString()); servicename=task.getResult().getDocuments().get(位置).get(“名称”).toString(); 整数价格=task.getResult().getDocuments().get(position).getLong(“价格”).intValue(); serviceArray.add(servicename); costArray.add(价格); ArrayListStylestarr=新的ArrayList(); Stylestarr=(ArrayList)task.getResult().getDocuments().get(position.get(“服务”); ArrayList StylesId=新的ArrayList(); style.sid.clear(); 对于(int i=0;i1){ 成本=selectedServiceCost.get(0)+selectedServiceCost.get(1); }否则{ 成本=selectedServiceCost.get(0); } 退货成本; } 公共整数getDurationArr(){ 整数持续时间=空; 如果(持续时间arr.size()>1){ duration=durationArr.get(0)+durationArr.get(1); }否则{ duration=durationArr.get(0); } 返回时间; } 公共阵列列表GetSelectedStyleStId(){ 返回所选样式ID; } @凌驾 public int getItemCount(){ 返回计数; } 私有类listViewHolder扩展了RecyclerView.ViewHolder{ 私有复选框; 私有文本视图servicenameTv,serviceCost; 整数计数=0; 字符串strService; 公共列表视图持有者(最终视图项视图){ 超级(项目视图); 试一试{ servicenameTv=(TextView)itemView.findViewById(R.id.damerServiceTV); serviceCost=(TextView)itemView.findViewById(R.id.damerRsTV); checkBox=(checkBox)itemviewbyd(R.id.checkBox); }捕获(例外e){ e、 printStackTrace(); } } } }

复选框选择和取消选择 package com.example.adapter; 导入android.content.Context; 导入android.support.v7.widget.RecyclerView; 导入android.util.Log; 导入android.util.SparseBooleanArray; 导入android.view.LayoutInflater; 导入android.view.view; 导入android.view.ViewGroup; 导入android.widget.CheckBox; 导入android.widget.CompoundButton; 导入android.widget.TextView; 导入android.widget.Toast; 导入com.example.aayushchaubey.meetdax.R; 导入com.google.android.gms.tasks.Task; 导入com.google.firebase.firestore.QuerySnapshot; 导入java.util.ArrayList; 导入java.util.HashMap; 公共类DifferentGenderServicesAdapter2扩展了RecyclerView.Adapter{ 私人任务; 字符串id,servicename; ArrayList serviceArray=新的ArrayList(); ArrayList costArray=新的ArrayList(); ArrayList StyleStidarray=新ArrayList(); ArrayListdurationArray=新的ArrayList(); TextView服务电视、durationTv; 整数计数=0; 字符串strService; ArrayList keyArr=新的ArrayList(); ArrayListserviceDocumentId=新的ArrayList(); ArrayList SelectedServiceId=新的ArrayList(); ArrayList SelectedServiceArray=新建ArrayList(); ArrayList SelectedServiceCost=新建ArrayList(); ArrayListdurationArr=新的ArrayList(); 字符串serviceId、strStylist、strDuration; ArrayList Styleist=新的ArrayList(); ArrayList SelectedStyleStId=新建ArrayList(); 公共差异EnderservicesAdapter2(任务任务、ArrayList id、TextView服务STV、TextView持续时间TV){ this.task=任务; this.serviceTv=servicesTv; this.durationTv=durationTv; this.serviceDocumentId=id; count=task.getResult().size(); } @凌驾 public RecyclerView.ViewHolder onCreateViewHolder(视图组父级,int-viewType){ View=LayoutFlater.from(parent.getContext()).flate(R.layout.services_项,parent,false); 返回新的DifferentGenderServicesAdapter2.listViewHolder(视图); } @凌驾 公共无效onBindViewHolder(最终RecyclerView.ViewHolder,最终整型位置){ 试一试{ ((listViewHolder)holder.servicenameTv.setText(task.getResult().getDocuments().get(position.get(“name”).toString()); ((listViewHolder)holder.serviceCost.setText(task.getResult().getDocuments().get(position.get(“price”).toString()); servicename=task.getResult().getDocuments().get(位置).get(“名称”).toString(); 整数价格=task.getResult().getDocuments().get(position).getLong(“价格”).intValue(); serviceArray.add(servicename); costArray.add(价格); ArrayListStylestarr=新的ArrayList(); Stylestarr=(ArrayList)task.getResult().getDocuments().get(position.get(“服务”); ArrayList StylesId=新的ArrayList(); style.sid.clear(); 对于(int i=0;i1){ 成本=selectedServiceCost.get(0)+selectedServiceCost.get(1); }否则{ 成本=selectedServiceCost.get(0); } 退货成本; } 公共整数getDurationArr(){ 整数持续时间=空; 如果(持续时间arr.size()>1){ duration=durationArr.get(0)+durationArr.get(1); }否则{ duration=durationArr.get(0); } 返回时间; } 公共阵列列表GetSelectedStyleStId(){ 返回所选样式ID; } @凌驾 public int getItemCount(){ 返回计数; } 私有类listViewHolder扩展了RecyclerView.ViewHolder{ 私有复选框; 私有文本视图servicenameTv,serviceCost; 整数计数=0; 字符串strService; 公共列表视图持有者(最终视图项视图){ 超级(项目视图); 试一试{ servicenameTv=(TextView)itemView.findViewById(R.id.damerServiceTV); serviceCost=(TextView)itemView.findViewById(R.id.damerRsTV); checkBox=(checkBox)itemviewbyd(R.id.checkBox); }捕获(例外e){ e、 printStackTrace(); } } } },java,android,Java,Android,这是我用来填充数组和复选框的recycleradapter。我想为所选项目设置文本。如果我取消选择这些项目,我想从textview中删除文本。当我选择一个项目时,选择和取消选择工作正常。如果我有多个项目,或者如果我选择和取消选择的次数是它不工作的次数,则给出索引错误是否喜欢e这是:- package com.example.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView

这是我用来填充数组和复选框的recycleradapter。我想为所选项目设置文本。如果我取消选择这些项目,我想从textview中删除文本。当我选择一个项目时,选择和取消选择工作正常。如果我有多个项目,或者如果我选择和取消选择的次数是它不工作的次数,则给出索引错误

是否喜欢e这是:-

package com.example.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import com.example.aayushchaubey.meetdax.R;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.QuerySnapshot;

import java.util.ArrayList;
import java.util.HashMap;

public class DifferentGenderServicesAdapter2 extends RecyclerView.Adapter {

    private Task<QuerySnapshot> task;
    String id, servicename;
    ArrayList<String> serviceArray = new ArrayList<>();
    ArrayList<Integer> costArray = new ArrayList<>();
    ArrayList<ArrayList<String>> stylistIdArray = new ArrayList<>();
    ArrayList<Integer>durationArray=new ArrayList<>();

    TextView serviceTv, durationTv;
    int count = 0;
    String strService;
    ArrayList<String> keyArr = new ArrayList<>();
    ArrayList<String>serviceDocumentId=new ArrayList<>();
    ArrayList<String>selectedServiceId=new ArrayList<>();

    ArrayList<String>selectedServiceArray=new ArrayList<>();

    ArrayList<Integer>selectedServiceCost=new ArrayList<>();
    ArrayList<Integer>durationArr=new ArrayList<>();
    String serviceId,strStylist,strDuration;
    ArrayList<String>stylist=new ArrayList<>();
    ArrayList<ArrayList<String>>selectedStylistId=new ArrayList<>();

    public DifferentGenderServicesAdapter2(Task<QuerySnapshot> task, ArrayList<String> id, TextView servicesTv, TextView durationTv) {
        this.task = task;
        this.serviceTv = servicesTv;
        this.durationTv = durationTv;
        this.serviceDocumentId=id;
        count = task.getResult().size();
    }

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

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        try {
            ((listViewHolder) holder).servicenameTv.setText(task.getResult().getDocuments().get(position).get("name").toString());
            ((listViewHolder) holder).serviceCost.setText(task.getResult().getDocuments().get(position).get("price").toString());

            servicename = task.getResult().getDocuments().get(position).get("name").toString();
            Integer price = task.getResult().getDocuments().get(position).getLong("price").intValue();
            serviceArray.add(servicename);
            costArray.add(price);

            ArrayList<HashMap<String,String>>stylistArr=new ArrayList<>();
            stylistArr=(ArrayList<HashMap<String, String>>)task.getResult().getDocuments().get(position).get("services");
            ArrayList<String> stylistsId = new ArrayList<String>();

            stylistsId.clear();

            for (int i=0;i<stylistArr.size();i++){
                strStylist=stylistArr.get(i).get("stylist").toString();
                strDuration=stylistArr.get(i).get("duration").toString();
                stylistsId.add(strStylist);
                durationArray.add(Integer.parseInt(strDuration));
            }
            stylistIdArray.add(stylistsId);

            ((listViewHolder) holder).checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    if(((listViewHolder) holder).checkBox.isChecked()){
                        String service=serviceArray.get(position);
                        selectedServiceArray.add(service);
                        serviceTv.setText(selectedServiceArray.toString().replaceAll("\\[|\\]", ""));

                    }else {
                        selectedServiceArray.remove(position);
                        if (selectedServiceArray.size()== 0) {
                            serviceTv.setText("0");
                        } else {
                            serviceTv.setText(selectedServiceArray.toString());
                        }
                    }
                }
            });

            } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public ArrayList<String> getServiceId() {
        return selectedServiceId;
    }

    public ArrayList<String> getServices() {
        return selectedServiceArray;
    }

    public Integer getCostArray() {
        Integer cost = null;
        if(selectedServiceCost.size()>1){
            cost=selectedServiceCost.get(0)+selectedServiceCost.get(1);
        }else {
            cost=selectedServiceCost.get(0);
        }
        return cost;
    }

    public Integer getDurationArr() {
        Integer duration=null;
        if(durationArr.size()>1){
            duration=durationArr.get(0)+durationArr.get(1);
        }else {
            duration=durationArr.get(0);
        }
        return duration;
    }
    public ArrayList<ArrayList<String>> getSelectedStylistId() {
        return selectedStylistId;
    }

    @Override
    public int getItemCount() {
        return count;
    }
    private class listViewHolder extends RecyclerView.ViewHolder {

        private CheckBox checkBox;
        private TextView servicenameTv, serviceCost;
        int count = 0;
        String strService;

        public listViewHolder(final View itemView) {
            super(itemView);
            try {
                servicenameTv = (TextView) itemView.findViewById(R.id.damerServiceTV);
                serviceCost = (TextView) itemView.findViewById(R.id.damerRsTV);
                checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

您正试图在给定的
ReciclerView
选择中删除项目,但此位置错误,因为您正在执行以下操作:

if(checkbox.isChecked){
    String service=serviceArray.get(getAdapterPosition)
    selectedServiceArray.add(service);
    holder.serviceNameTv.setText(selectedServiceArray.toString);
}
else{
    selectedServiceArray.remove(getAdapterPosition);
if (selectedServiceArray.size = 0) {
 holder.serviceNameTv.setText("0");
} else{
 holder.serviceNameTv.setText(selectedServiceArray.toString);
}
因此,您不知道添加的位置,因为可能是此数组中的其他项。您必须请求删除对象,而不是位置。请尝试以下操作:

selectedServiceArray.add(service); 
if(checkbox.isChecked){
   String service=serviceArray.get(getAdapterPosition);
   selectedServiceArray.add(service);
   holder.serviceNameTv.setText(selectedServiceArray.toString);
} else {
  String service=serviceArray.get(getAdapterPosition);
  selectedServiceArray.remove(service);  
  holder.serviceNameTv.setText(selectedServiceArray.toString);
}