我是Android(Java)的firebase新手,想知道如何检查用户是否已存在于以下格式的数据库中:
gdb-2fbgg{
users{
Michael{
age: 20
height: 150
name: Michael
}
Bob{
age: 20
height: 150
name: Bob
}
}
}
Run Code Online (Sandbox Code Playgroud)
例如,按下按钮,我想查看firebase以查看用户名"Michael"是否存在(第一级迈克尔 - 而不是对象michael中的"michael".
谢谢
我想知道如何才能发现何时FirestoreRecyclerAdapter只有空。使用下面的代码,我可以发现它是否有一个或多个实例,但它不会告诉我什么时候里面没有对象。if(adapter.getItemCount == 0)每次都显示验证,因为适配器每次都通过0计数,所以显然这个功能不起作用。
那么如何才能发现它是否完全为空呢?
这是我的代码:
Query query = spotsCollection.whereEqualTo("cityId", cityId).limit(5);
FirestoreRecyclerOptions<Spots> options = new FirestoreRecyclerOptions.Builder<Spots>()
.setQuery(query, Spots.class)
.build();
FirestoreRecyclerAdapter<Spots, SpotViewHolder> adapter = new FirestoreRecyclerAdapter<Spots, SpotViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull SpotViewHolder spotViewHolder, int i, @NonNull Spots spots) {
if(i > 3)
// Do something with i > 3
}
@NonNull
@Override
public SpotViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.recycler_app_spots, parent, false);
return new SpotViewHolder(view);
}
};
if(adapter.getItemCount() == 0)
Toast.makeText(getContext(), "Empty", Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud)