我正在开发一个约会系统,我想在Recyvlerview中列出上传的约会,所以我创建了一个模型类,用于存储数据以及用于数据目的。此外,数据已经存在,我已经从AddVlueListiner确保了数据,因此以下是类和布局
列出约会类别
public class List_appointment extends AppCompatActivity {
private FirebaseAuth mAuth;
private DatabaseReference mReference;
private Button ChatButton;
private TextView StartBusinseTime, EndBusinessTime, StartAppointment, EdnAppointment;
private RecyclerView OwnerListAppointment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_appointment);
//Todo:Firebase Instance
mAuth = FirebaseAuth.getInstance();
String Uid = mAuth.getCurrentUser().getUid();
mReference = FirebaseDatabase.getInstance().getReference().child("Appointments").child(Uid);//make sure from this path
// mReference.addValueEventListener(new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// if (dataSnapshot.exists()){
// for (DataSnapshot snapshot : dataSnapshot.getChildren()){
// System.out.println("List owner appoinemt"+snapshot);
// }
// }
//
// }
//
// @Override
// public void onCancelled(DatabaseError databaseError) {
//
// }
// });
OwnerListAppointment = (RecyclerView) findViewById(R.id.OwnerListAppointment);
LinearLayoutManager OwnerLayoutManager = new LinearLayoutManager(this);
OwnerLayoutManager.setReverseLayout(true);
OwnerLayoutManager.setStackFromEnd(true);
OwnerListAppointment.setLayoutManager(OwnerLayoutManager);
}
public static class OwnerListAppointmentClass extends RecyclerView.ViewHolder {//class into class is called liner class
View mView;
public OwnerListAppointmentClass(View itemView) {
super(itemView);
mView = itemView;
}
public void setStartFirstAppoint(String startFirstAppoint) {
TextView StartAppointment = (TextView) mView.findViewById(R.id.StartAppointmet_Owner);
StartAppointment.setText(startFirstAppoint);
}
public void setEndSecondAppointment(String endSecondAppointment) {
TextView EndAppointment = (TextView) mView.findViewById(R.id.EndAppointment);
EndAppointment.setText(endSecondAppointment);
}
public void setAppointmentStuts(String appointmentStuts) {
TextView appointment = (TextView) mView.findViewById(R.id.EndAppointment_Owner);
appointment.setText(appointmentStuts);
}
}
private void DisplayListOfAppointments() {
FirebaseRecyclerAdapter<AddUserAppointment, List_appointment.OwnerListAppointmentClass> AppointmentRecyclerAdapter =
new FirebaseRecyclerAdapter<AddUserAppointment, OwnerListAppointmentClass>
(
AddUserAppointment.class,
R.layout.listappointmentclass,
OwnerListAppointmentClass.class,
mReference
)
{
@Override
protected void populateViewHolder(OwnerListAppointmentClass viewHolder, AddUserAppointment model, int position) {
final String SAppoinemtnKey = getRef(position).getKey();
viewHolder.setStartFirstAppoint(model.getStartFirstAppoint());
viewHolder.setEndSecondAppointment(model.getEndSecondAppointment());
viewHolder.setAppointmentStuts(model.getAppointmentStuts());
}
};
OwnerListAppointment.setAdapter(AppointmentRecyclerAdapter);
}
模块类
public class AddUserAppointment {
private String StartBusinse;
private String StartBusinseTime ;
private String EndBusinseTime ;
private String startFirstAppoint ;
private String endSecondAppointment ;
private String AppointmentStuts;
private String Uid;
private static ArrayList<AddUserAppointment>AppointmentList = new ArrayList<>();
public static ArrayList<AddUserAppointment> getAppointmentList() {
return AppointmentList;
}
public AddUserAppointment() {
////empty
}
public AddUserAppointment(String startBusinse, String startBusinseTime, String endBusinseTime, String startFirstAppoint, String endSecondAppointment, String appointmentStuts, String uid) {
StartBusinse = startBusinse;
StartBusinseTime = startBusinseTime;
EndBusinseTime = endBusinseTime;
this.startFirstAppoint = startFirstAppoint;
this.endSecondAppointment = endSecondAppointment;
AppointmentStuts = appointmentStuts;
Uid = uid;
}
public String getUid() {
return Uid;
}
public void setUid(String uid) {
Uid = uid;
}
public String getStartBusinse() {
return StartBusinse;
}
public void setStartBusinse(String startBusinse) {
StartBusinse = startBusinse;
}
public String getStartBusinseTime() {
return StartBusinseTime;
}
public void setStartBusinseTime(String startBusinseTime) {
StartBusinseTime = startBusinseTime;
}
public String getEndBusinseTime() {
return EndBusinseTime;
}
public void setEndBusinseTime(String endBusinseTime) {
EndBusinseTime = endBusinseTime;
}
public String getStartFirstAppoint() {
return startFirstAppoint;
}
public void setStartFirstAppoint(String startFirstAppoint) {
this.startFirstAppoint = startFirstAppoint;
}
public String getEndSecondAppointment() {
return endSecondAppointment;
}
public void setEndSecondAppointment(String endSecondAppointment) {
this.endSecondAppointment = endSecondAppointment;
}
public String getAppointmentStuts() {
return AppointmentStuts;
}
public void setAppointmentStuts(String appointmentStuts) {
AppointmentStuts = appointmentStuts;
}
}
答案 0 :(得分:0)
首先,RecyclerView
的实现不是标准的;猜测其Firebase UI RecyclerView,尝试通过创建您自己的类并扩展Firebase RecyclerView来实现它。
第二,您从未调用过方法DisplayListOfAppointments()
,因此没有创建ViewHolder对象,也没有将其附加到RecyclerView
,即同一方法的最后一行:< / p>
OwnerListAppointment.setAdapter(AppointmentRecyclerAdapter)