简体   繁体   English

RecyclerView 未从 firebase 数据库中获取数据

[英]RecyclerView not fetching data from firebase database

I'm making an app where i have to fetch some data from firebase and show in recyclerview.我正在制作一个应用程序,我必须从 firebase 获取一些数据并在 recyclerview 中显示。 But the textView fields remain empty and show no data.但是 textView 字段仍然为空并且不显示任何数据。 Below is the db structure.下面是数据库结构。 I want to get the data of the nodes under "AlphabetMatching" but failing to get it.我想获取“AlphabetMatching”下节点的数据,但未能获取。 The Recycler show the layout i have made for the rows, but no data from the database. Recycler 显示了我为行所做的布局,但没有来自数据库的数据。

在此处输入图像描述


Activity Class:活动 Class:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_alphabet_matching_perf);



    mlinearLayoutManager= new LinearLayoutManager(this);
    //mlinearLayoutManager.setReverseLayout(true);
   // mlinearLayoutManager.setStackFromEnd(true);


    recyclerView=findViewById(R.id.am_recycler);



    db_ref= FirebaseDatabase.getInstance().getReference("Performance");
    user= FirebaseAuth.getInstance().getCurrentUser();
    userID=user.getUid();

    alphabetMatchingPerfRef= db_ref.child(userID).child("AlphabetMatching");


    //Toast.makeText(this, alphabetMatchingPerfRef.toString(), Toast.LENGTH_SHORT).show();



    showData();




}

public void showData()
{

    options=new FirebaseRecyclerOptions.Builder<amaw>().setQuery(alphabetMatchingPerfRef,amaw.class).build();

    firebaseRecyclerAdapter= new FirebaseRecyclerAdapter<amaw, ViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull amaw model) {
            holder.setDetails(getApplicationContext(),model.getDate(),model.getTime(),model.getScore());


        }

        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View itemView= LayoutInflater.from(parent.getContext()).inflate(R.layout.performancelayout,parent,false);

            ViewHolder holder = new ViewHolder(itemView);
            return holder;
        }
    };

    recyclerView.setLayoutManager(mlinearLayoutManager);
    firebaseRecyclerAdapter.startListening();
    recyclerView.setAdapter(firebaseRecyclerAdapter);
}

VIEWHOLDER CLASS:取景器 CLASS:

public class ViewHolder extends RecyclerView.ViewHolder {

View mView;



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


    mView=itemView;

    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });


}

public void setDetails(Context ctx,String date, String time, String score)
{
    TextView mdate=mView.findViewById(R.id.date_box);
    TextView mtime=mView.findViewById(R.id.time_box);
    TextView mscore=mView.findViewById(R.id.score_box);
}

} }


AMAW CLASS AMAW CLASS

public class amaw {

String date;
String score;
String time;

String username;

public amaw(String datee, String time, String score) {
    this.date = datee;
    this.time = time;
    this.score = score;
}

public amaw() {

}
public String getDate() {
    return date;
}

public void setDate(String datee) {
    this.date = datee;
}


public String getScore() {
    return score;
}

public void setScore(String score) {
    this.score = score;
}

public String getTime() {
    return time;
}

public void setTime(String time) {
    this.time = time;
}

} }

Change this:改变这个:


public void setDetails(Context ctx,String date, String time, String score)
{
    TextView mdate=mView.findViewById(R.id.date_box);
    TextView mtime=mView.findViewById(R.id.time_box);
    TextView mscore=mView.findViewById(R.id.score_box);
}

Into this:进入这个:


public void setDetails(Context ctx,String date, String time, String score)
{
    TextView mdate=mView.findViewById(R.id.date_box);
    TextView mtime=mView.findViewById(R.id.time_box);
    TextView mscore=mView.findViewById(R.id.score_box);
    mdate.setText(date);
    mtime.setText(time);
    mscore.setText(score);
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM