gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:16:13 25 4
gpt4 key购买 nike

我正在制作一个应用程序,我必须从 firebase 获取一些数据并在 recyclerview 中显示。但 textView 字段仍为空并且不显示任何数据。下面是数据库结构。我想获取“AlphabetMatching”下节点的数据,但未能获取。回收器显示我为行所做的布局,但没有来自数据库的数据。

enter image description here

<小时/>

Activity 类别:

    @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);
}
<小时/>

浏览者类别:

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);
}

}

<小时/>

阿玛级

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;
}

}

最佳答案

更改此:


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);
}

进入此:


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);
}

关于java - RecyclerView未从firebase数据库中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58963581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com