我的Firebase RecyclerView
花费了太多时间来加载数据。我在许多片段中使用RecyclerView
,但它们不会出现任何问题。但我不知道这里有什么问题。它会在5分钟或更长时间后加载数据。有人知道这个问题吗?
我的主要片段类:
public class UserPrescriptionView extends Fragment {
private DatabaseReference dataRef;
private String uid;
private FirebaseAuth mAuth;
private Query mQuery;
private RecyclerView recycle;
private TextView noCnslt,dctName,cnsltDate;
private ProgressBar progress;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
container, @Nullable Bundle savedInstanceState) {
if (container!=null){
container.removeAllViews();
}
View v=inflater.inflate(R.layout.activity_user_prescription_view,container,false);
mAuth=FirebaseAuth.getInstance();
dataRef= FirebaseDatabase.getInstance().getReference();
uid=mAuth.getCurrentUser().getUid();
recycle= (RecyclerView) v.findViewById(R.id.user_prscptn_view_recycle);
noCnslt= (TextView) v.findViewById(R.id.activity_user_prescription_noCnslt);
recycle.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
progress= (ProgressBar) v.findViewById(R.id.user_prscptn_progress);
noCnslt.setVisibility(View.GONE);
llm.setOrientation(LinearLayoutManager.VERTICAL);
recycle.setLayoutManager(llm);
recycle.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));
dctName= (TextView) v.findViewById(R.id.user_prscptn_dctName);
cnsltDate= (TextView) v.findViewById(R.id.user_prscptn_cnsltOn);
dctName.setVisibility(View.GONE);
cnsltDate.setVisibility(View.GONE);
return v;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mQuery=dataRef.child("Medical Record").orderByChild("uid").equalTo(uid);
FirebaseRecyclerAdapter<DocPrcptn,DocPrcptnViewHolder> adapter=new FirebaseRecyclerAdapter<DocPrcptn, DocPrcptnViewHolder>(
DocPrcptn.class,
R.layout.user_prscrptn_view,
DocPrcptnViewHolder.class,
mQuery
) {
@Override
protected void populateViewHolder(DocPrcptnViewHolder viewHolder, final DocPrcptn model, final int position) {
progress.setVisibility(View.GONE);
dctName.setVisibility(View.VISIBLE);
cnsltDate.setVisibility(View.VISIBLE);
viewHolder.setDate(model.getDate().substring(0,11));
viewHolder.setDoctor("Dr "+model.getDoctor());
final String key=getRef(position).getKey();
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction ft=getFragmentManager().beginTransaction();
Prescription pc=new Prescription();
Bundle b=new Bundle();
b.putString("key",key);
pc.setArguments(b);
ft.replace(R.id.activity_user_prescription_recycle,pc);
ft.addToBackStack(null);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
});
}
@Override
public void onDataChanged() {
if (getItemCount()==0){
progress.setVisibility(View.GONE);
noCnslt.setVisibility(View.VISIBLE);
}
super.onDataChanged();
}
};
recycle.setAdapter(adapter);
}
public static class DocPrcptnViewHolder extends RecyclerView.ViewHolder{
private TextView docName,docDate;
public DocPrcptnViewHolder(View itemView) {
super(itemView);
docName= (TextView) itemView.findViewById(R.id.user_prscptn_view_name);
docDate= (TextView) itemView.findViewById(R.id.user_prscptn_view_date);
}
public void setDoctor(String name){
docName.setText(name);
}
public void setDate(String date){
docDate.setText(date);
}
}
}
我的模特课:
public class DocPrcptn {
public DocPrcptn() {
}
public String doctor,date;
public DocPrcptn(String doctor, String date) {
this.doctor = doctor;
this.date = date;
}
public String getDoctor() {
return doctor;
}
public void setDoctor(String doctor) {
this.doctor = doctor;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
任何线索?感谢。