FirebaseRecycelerAdapter始终显示空白屏幕

时间:2019-03-17 15:56:47

标签: java android firebase firebase-realtime-database

enter image description here当我运行代码时,它显示为黑屏,没有错误,没有。我的代码在这里没有发现任何问题。不知道主要问题是什么?谁能帮我找到答案。这是我的完整代码。我使用FirebaseRecycelerAdapter,但在这里不起作用。 FirebaseRecycelerAdapter不显示任何数据。 Android Studio日志中没有错误。谁能帮助我解决这个问题?我想从Firebase数据库中获取数据,所以我使用FirebaseRecycelerAdapter,但在这里不起作用。

  Main2Activity
    package net.skillbooster.facebookfreelancingearnfromfacebook;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class Main2Activity extends AppCompatActivity {
    private RecyclerView recyclerView;
    DatabaseReference databaseReference;
    FirebaseRecyclerOptions<FinalList> options;
    FirebaseRecyclerAdapter<FinalList,ViewHolderFinal> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        recyclerView = findViewById(R.id.recyclerview_layout);
        databaseReference = FirebaseDatabase.getInstance().getReference().child("Withdraw");
       recyclerView.setLayoutManager(new LinearLayoutManager(this));
       recyclerView.setHasFixedSize(true);
       options = new FirebaseRecyclerOptions.Builder<FinalList>().setQuery(databaseReference,FinalList.class).setLifecycleOwner(this).build();

        adapter = new FirebaseRecyclerAdapter<FinalList, ViewHolderFinal>(options) {
            @Override
            protected void onBindViewHolder(@NonNull ViewHolderFinal holder, int position, @NonNull FinalList model) {

                holder.amount.setText(model.getAmount());
                holder.number.setText(model.getNumber());
            }

            @NonNull
            @Override
            public ViewHolderFinal onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

                View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_row,viewGroup,false);
                return new ViewHolderFinal(view);
            }
        };

        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if(!(adapter == null)){
            adapter.startListening();
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if(!(adapter == null)){

            adapter.stopListening();
        }
    }
}




  ViewHoldeFinal.class
  package net.skillbooster.facebookfreelancingearnfromfacebook;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

public class ViewHolderFinal extends RecyclerView.ViewHolder {
    TextView amount,number;

    public ViewHolderFinal(@NonNull View itemView) {
        super(itemView);

        amount = itemView.findViewById(R.id.layout_amount);
        number = itemView.findViewById(R.id.layout_number);
    }

}



    FinalList.class

    package net.skillbooster.facebookfreelancingearnfromfacebook;

public class FinalList {
    String amount;
    String number;
    String userid;
    String way;

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getWay() {
        return way;
    }

    public void setWay(String way) {
        this.way = way;
    }

    public FinalList(String amount, String number, String userid, String way) {
        this.amount = amount;
        this.number = number;
        this.userid = userid;
        this.way = way;
    }

    public FinalList() {
    }
}

0 个答案:

没有答案