如何知道FirebaseRecyclerAdapter查询是否为零,是否存在
我在
上找到了一些说明https://github.com/firebase/FirebaseUI-Android/tree/master/database
它说:
数据和错误事件
使用FirebaseRecyclerAdapter时,您可以 希望每次数据更改时或有数据更改时执行一些操作 一个错误。为此,请重写onDataChanged()和onError() 适配器的方法:
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(options) {
// ...
@Override
public void onDataChanged() {
// Called each time there is a new data snapshot. You may want to use this method
// to hide a loading spinner or check for the "no documents" state and update your UI.
// ...
}
@Override
public void onError(DatabaseError e) {
// Called when there is an error getting data. You may want to update
// your UI to display an error message to the user.
// ...
}
};
当我尝试如下使用时:
mAdapter = new FirebaseRecyclerAdapter<Place, PlaceViewHolder>(options)
{
@Override
public void onDataChanged(DataSnapshot dataSnapshot)
{
// Called each time there is a new data snapshot. You may want to use this method
// to hide a loading spinner or check for the "no documents" state and update your UI.
// ...
if (dataSnapshot.exists())
{
Log.d(TAG,"data exists");
}
else
{
Log.d(TAG,"No data exists");
}
}
@NonNull
@Override
public PlaceViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i)
{
错误消息是:
方法不会从其超类覆盖方法
那我该如何解决这个问题,谢谢。
答案 0 :(得分:1)
我从另一个页面找到了答案:
https://www.programcreek.com/java-api-examples/?api=com.firebase.ui.database.FirebaseRecyclerAdapter
@Override
public void onDataChanged()
{
// Called each time there is a new data snapshot. You may want to use this method
// to hide a loading spinner or check for the "no documents" state and update your UI.
// ...
if (getItemCount() == 0)
{
Log.d(TAG,"No data exists");
}
else
{
Log.d(TAG,"data exists");
}
}