【发布时间】:2019-03-22 04:59:36
【问题描述】:
我正在尝试使用 android studio 获取 firebase 数据并将其显示在屏幕上。我正在尝试将数据库中与其相关的任何内容显示到 RecyclerView。但是数据没有返回,也没有任何显示(没有错误声明)。任何想法为什么?
private void firebaseLotSearch() {
Toast.makeText(BuyingParking.this,"Started Search",Toast.LENGTH_LONG).show();
Query query = mUserDatabase.startAt(searchText).endAt(searchText+"\uf8ff");
FirebaseRecyclerOptions<Lot_Location> options =
new FirebaseRecyclerOptions.Builder<Lot_Location>()
.setQuery(query, Lot_Location.class)
.build();
// Lot_Location.class,R.layout.list_layout,LotViewHolder.class,mUserDatabase
FirebaseRecyclerAdapter<Lot_Location,LotViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Lot_Location, LotViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull LotViewHolder holder, int position, @NonNull Lot_Location model) {
holder.setDetails(model.getLocation(),model.getAdmin(),model.getPrice());
}
@NonNull
@Override
public LotViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return null;
}
};
searchParking.setAdapter(firebaseRecyclerAdapter);
}
public class LotViewHolder extends RecyclerView.ViewHolder{
public LotViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
}
public void setDetails(String location,String admin,String price)
{
TextView m_location = (TextView)mView.findViewById(R.id.Lot);
TextView m_admin = (TextView)mView.findViewById(R.id.Admin);
TextView m_price = (TextView)mView.findViewById(R.id.price);
m_location.setText(location);
m_admin.setText(admin);
m_price.setText(price);
}
}
【问题讨论】:
-
您可以设置breakpoint 并调查会发生什么
-
您似乎没有在代码中的任何位置调用
startListening(),这是 FirebaseUI 开始观察数据库所必需的。请检查副本。
标签: java android firebase firebase-realtime-database