2
我想從我的Firebase數據庫檢索數據,但我的屏幕沒有顯示任何內容。我沒有看到任何錯誤,所以我不知道爲什麼沒有發生。任何人都能發現任何錯誤?我通過一個stackoverflow成員的幫助來跟蹤FirebaseUI指南。這些數據應顯示在街上,在屏幕上,用戶Android - RecyclerView不工作
片段:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_stopandmap, container, false);
Query keyQuery = FirebaseDatabase.getInstance().getReference("/Addresses/Street 10/users");
DatabaseReference dataRef = FirebaseDatabase.getInstance().getReference("/User");
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
FirebaseRecyclerOptions<User> options = new FirebaseRecyclerOptions.Builder<User>()
.setIndexedQuery(keyQuery, dataRef, User.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<User, BetViewHolder>(options) {
@Override
public BetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_row, parent, false);
return new BetViewHolder(view);
}
@Override
protected void onBindViewHolder(BetViewHolder holder, int position, User model) {
holder.setUserName(model.getUsername());
}
};
recyclerView.setAdapter(adapter);
return rootView;
}
public static class BetViewHolder extends RecyclerView.ViewHolder {
TextView tw;
public BetViewHolder(View itemView) {
super(itemView);
tw = (TextView) itemView.findViewById(R.id.usersTextview);
}
public void setUserName(String username) {
tw.setText("Hej" + username);
Log.e("Activity", "In Vehicle " + username);
}
}
用戶等級:
public class User {
private String username;
private String usertype;
public User() {
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsertype() {
return usertype;
}
public void setUsertype(String usertype) {
this.usertype = usertype;
}
}
調試和檢查適配器的內容,如果有我檢查適配器是否是空的,adapter.getItemCount任何數據或不 – nomag
和原來它是空的。我不明白爲什麼它是空的 – JDoe
這是因爲keyQuery和dataRef指向不同的firebase節點。兩者都應該指向同一個父節點。 –