提问者:小点点

无法解析方法“getRef(int)”


这是我想使用. RemoveValue()从Firebase中删除数据的错误;但无法使用.child(getRef(位置).getKey())获取孩子内部的密钥;它说“无法解析方法'getRef(int)'”

我试图用吸气剂拿到钥匙

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



Context context;

ArrayList<User> list;

DataSnapshot snapshot;

FirebaseFirestore firestore;
FirebaseAuth auth;

DatabaseReference reference;




//for search
public void setFilteredList(ArrayList<User> filteredList){
    this.list = filteredList;
    notifyDataSetChanged();
    }

public RecyclerContactAdapter(Context context, ArrayList<User>list){

     this.context = context;
     this.list = list;


    }




    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       View view = LayoutInflater.from(context).inflate(R.layout.contact_row, parent, false);


        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        User user = list.get(position);
//        String id1 = list.get(position).getKey();

        holder.name.setText(user.getName());
        holder.chn.setText(user.getChn());
        holder.shn.setText(user.getShn());
        holder.phone.setText(user.getPhone());

        holder.hostel_optn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            FirebaseDatabase.getInstance().getReference().child("HostelSwappingDatabase")
                    .child(getRef(position).getKey())
                    .removeValue();


            }
        });

        holder.setIsRecyclable(false);


    }




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


//
    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

//
    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView name, chn, shn, phone;
        ImageView hostel_optn;

        public ViewHolder(View itemView){
           super(itemView);

           name = itemView.findViewById(R.id.name);
           chn = itemView.findViewById(R.id.chn);
           shn = itemView.findViewById(R.id.shn);
           phone = itemView.findViewById(R.id.phone);


           hostel_optn = itemView.findViewById(R.id.hostel_optn);

        }








    }

}


共1个答案

匿名用户

要从Firebase中删除任何数据实例,必须实现此处提到的FirebaseRecyclerAdapter

还可以从该视频中获得帮助,如果需要,请单击此处。