此问题已在此处找到答案:
firebase android列表视图未显示(1个答案)
firebase实时数据库:未填充回收器视图(1个答案)
17分钟前关门。
我正在尝试从firestore集合中获取学生数据,然后将其显示在回收器视图我的firestore集合和文档中:集合名称是学校代码,文档包含学生信息
模范班:(学生模范班)
package com.example.firestooredemo;
import android.util.Log;
import java.sql.Timestamp;
import java.util.HashMap;
public class Student_Data_Model {
private String Form_name,StudentName,Subject;
private Timestamp Ts;
private long School_ID,Std;
private HashMap<String, String> QnA;
private Student_Data_Model(){}
private Student_Data_Model(long Std,String Form_name,String StudentName,String Subject,Timestamp Ts,long School_ID,HashMap<String, String> QnA){
this.Std=Std;
this.Form_name=Form_name;
this.QnA=QnA;
this.StudentName=StudentName;
this.Subject=Subject;
this.Ts=Ts;
this.School_ID=School_ID;
}
public String getStd() {
Log.d("ValueCheck", "Standard : "+Std);
return String.valueOf(Std);
}
public void setStd(long std) {
Std = std;
}
public String getForm_name() {
Log.d("ValueCheck", "FormNAme : "+Form_name);
return Form_name;
}
public void setForm_name(String form_name) {
Form_name = form_name;
}
public String getStudentName() {
Log.d("ValueCheck", "StudentNAme : "+StudentName);
return StudentName;
}
public void setStudentName(String studentName) {
StudentName = studentName;
}
public String getSubject() {
Log.d("ValueCheck", "Subject : "+Subject);
return Subject;
}
public void setSubject(String subject) {
Subject = subject;
}
public String getTs() {
return Ts.toString();
}
public void setTs(Timestamp ts) {
Ts = ts;
}
public String getSchool_ID() {
Log.d("ValueCheck", "SchoolID : "+School_ID);
return String.valueOf(School_ID);
}
public void setSchool_ID(long school_ID) {
School_ID = school_ID;
}
public HashMap<String, String> getQnA() {
return QnA;
}
public void setQnA(HashMap<String, String> qnA) {
QnA = qnA;
}
}
activity.java:
package com.example.firestooredemo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import java.util.List;
public class DisplayRecord extends AppCompatActivity {
TextView Record_Title,DemoD;
private FirebaseFirestore Fs;
private RecyclerView FSList;
private FirestoreRecyclerAdapter<Student_Data_Model,Student_View_Holder> F_Adapter;
String S_ID,Student;
List<sdm> stud;
int S_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_record);
FSList=(RecyclerView) findViewById(R.id.RCView);
FSList.setHasFixedSize(true);
FSList.setLayoutManager(new LinearLayoutManager(this));
Intent intent = getIntent();
Fs=FirebaseFirestore.getInstance();
Record_Title= (TextView) findViewById(R.id.RecordTitle);
S_ID = intent.getStringExtra("School ID");
Record_Title.setText("Records of "+S_ID);
Log.d("Datacheck","School :"+S_ID);
S_id=Integer.parseInt(S_ID);
String TAG="Datacheck";
Fs.collection("EM_DEMO").document("10th_STD").collection(S_ID)
.whereEqualTo("Form Name","Tourism, Transport and Communication3")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData().toString());
Student=Student+document.getLong("Class")+"\n"+document.get("Subject")+"\n"+document.get("Form Name")+"\n-----\n";
// stud.add(document.toObject(s1));
Log.d("IMOP",Student);
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
//Query Part
Query Q=Fs.collection("EM_DEMO").document("10th_STD").collection(S_ID).whereEqualTo("Form Name","Tourism, Transport and Communication3");
// Recycler view Display
FirestoreRecyclerOptions<Student_Data_Model> Opt=new FirestoreRecyclerOptions.Builder<Student_Data_Model>()
.setQuery(Q,Student_Data_Model.class)
.build();
F_Adapter = new FirestoreRecyclerAdapter<Student_Data_Model, Student_View_Holder>(Opt) {
@NonNull
@Override
public Student_View_Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View V= LayoutInflater.from(parent.getContext()).inflate(R.layout.student_data,parent,false);
return new Student_View_Holder(V);
}
@Override
protected void onBindViewHolder(@NonNull Student_View_Holder holder, int position, @NonNull Student_Data_Model model) {
holder.StudentName.setText(model.getStudentName());
holder.Standard.setText(model.getStd());
holder.SchoolID.setText(model.getSchool_ID()+"");
holder.Subject.setText(model.getSubject());
holder.FormName.setText(model.getForm_name());
// holder.Time.setText(model.getTs()+"");
}
};
FSList.setAdapter(F_Adapter);
//View Holder
}
private class Student_View_Holder extends RecyclerView.ViewHolder {
private TextView StudentName,Standard,Subject,SchoolID,FormName,Time;
public Student_View_Holder(@NonNull View itemView) {
super(itemView);
StudentName = itemView.findViewById(R.id.StudentName);
Standard = itemView.findViewById(R.id.Std);
Subject = itemView.findViewById(R.id.Sub);
SchoolID = itemView.findViewById(R.id.SchoolID);
FormName = itemView.findViewById(R.id.FormName);
Time = itemView.findViewById(R.id.Timestamp);
}
}
@Override
protected void onStart() {
super.onStart();
F_Adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
if(F_Adapter!= null){
F_Adapter.stopListening();
}
}
}
学生资料设计:xml设计截图
但应用内回收器视图仅显示获取的主题值,
应用程序输出
我在student data model类中放置了一些日志消息,以检查是否正在提取数据。但这些日志甚至没有显示日志消息:
带标记的日志:datacheck
带有标记的日志:imop
请帮忙做这个,
提前谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!