Android无法自动从Firebase检索数据并显示到回收者视图

时间:2020-09-13 11:51:50

标签: android firebase firebase-realtime-database firebaseui

我的应用无法自动从Firebase检索数据。它必须从子菜单返回,然后再次单击菜单以进入并显示到“回收者”视图中。其他活动效果很好,但是在此活动中无法自动撤退。有什么建议吗?

Datarefprovfoto = FirebaseDatabase.getInstance().getReference("PhotoProv");
    recyclerView_daftarprovfoto=findViewById(R.id.rec_daftarphotoprov);
    recyclerView_daftarprovfoto.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    recyclerView_daftarprovfoto.setHasFixedSize(true);

    Load_DataProvFoto();

这是功能加载数据并显示给回收站

public void Load_DataProvFoto(){
    optionsprovfoto=new FirebaseRecyclerOptions.Builder<ProvinsiFoto>().setQuery(Datarefprovfoto, ProvinsiFoto.class).build();
    adapterprovfoto=new FirebaseRecyclerAdapter<ProvinsiFoto, MyViewHolder_Provinsifoto>(optionsprovfoto) {

        @Override
        protected void onBindViewHolder(@NonNull MyViewHolder_Provinsifoto holder, final int position, @NonNull final ProvinsiFoto model) {
            holder.textView_namaproffoto.setText(model.getNama());
            holder.textView_deskripsiprovfoto.setText(model.getDeskripsi());
            Picasso.get().load(model.getBg()).into(holder.imageView_bgprovfoto);

            holder.imageView_bgprovfoto.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle= new Bundle();
                    bundle.putString("provinsi",model.getNama());
                    bundle.putString("deskripsi",model.getDeskripsi());
                    bundle.putString("bg",model.getBg());

                    Intent intent= new Intent(Photosession.this, PhotosessionDaftar.class); //THIS BISA PAKAI CONTEXT KALAU DI BEDA CLASS
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });

        }

        @NonNull
        @Override
        public MyViewHolder_Provinsifoto onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.rec_photoprov,parent,false);
            return new MyViewHolder_Provinsifoto(v);
        }
    };
    adapterprovfoto.startListening();
    recyclerView_daftarprovfoto.setAdapter(adapterprovfoto);
}

0 个答案:

没有答案