我正在制作一个应用程序,其中我必须从Firebase中获取一些数据并在recyclerview中显示。但是textView字段保持为空,不显示任何数据。下面是数据库结构。我想获取“ AlphabetMatching”下节点的数据,但无法获取。回收站显示我为行制作的布局,但没有数据库中的数据。
活动类别:
@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:
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
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;
}
}
答案 0 :(得分:1)
更改此:
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);
}