问题描述
我使用FirebaseUI FirebaseListAdapter。加载数据需要一些时间,我想显示一个旋转的圆圈。通过将视图可见性设置为在populateView中不可见,我可以关闭进度条,但如果没有视图来填充,则不起作用。如何处理这个问题? 更新:现在的FirebaseUI适配器有一个 onDataChanged()
方法,您可以覆盖以检测何时加载一组数据。
请参阅。从那里:
FirebaseUI示例应用程序覆盖 onDataChanged()
来隐藏它的加载指标:
public void onDataChanged(){
//如果没有聊天消息,则显示邀请用户添加消息的视图。
mEmptyListMessage.setVisibility(getItemCount()== 0?View.VISIBLE:View.GONE);
原始答案 FirebaseUI列表适配器在内部使用Firebase 您可以通过将附加的值侦听器附加到引用/查询来检测这种情况你传递给适配器。 I use the FirebaseUI FirebaseListAdapter. It takes some time to load the data and I want to show a spinning circle. I can dismiss the progress bar in by setting the view visibility to invisible in the populateView, but it doesn't work if there is no view to populate. How to handle this? Update: the FirebaseUI adapters nowadays have an See the source code on github. From there: The FirebaseUI sample app overrides Original answer The FirebaseUI list adapters internally use a Firebase You can detect this situation by attaching an additional value listener to the reference/query that you pass into the adapter. 这篇关于即使FirebaseListAdapter中没有视图,也要关闭进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
ChildEventListener
。这个聆听者只会为相关的小孩事件而发火。如果没有孩子,则不会触发事件。
DatabaseReference list = mDatabase.child(messages);
showSpinner();
mAdapter = new FirebaseListAdapter< Message>(......,list){
void populateView(View view,Message message,int position){
//第一条消息被加载
hideSpinner();
}
});
list.addListenerForSingleValueEvent(new ValueEventListener(){
@Override $ b $ public void onDataChange(DataSnapshot dataSnapshot){
//初始数据被加载(即使没有)
hideSpinner();
}
@Override
public void onCancelled(DatabaseError databaseError){
Log.w(TAG,onCancelled,databaseError。 toException());
}
});
onDataChanged()
method that you can override to detect when they're done loading a set of data. onDataChanged()
to hide its "loading" indicator:public void onDataChanged() {
// If there are no chat messages, show a view that invites the user to add a message.
mEmptyListMessage.setVisibility(getItemCount() == 0 ? View.VISIBLE : View.GONE);
}
ChildEventListener
. This listener only fires for relevant child events. If there are no children, no event will fire.DatabaseReference list = mDatabase.child("messages");
showSpinner();
mAdapter = new FirebaseListAdapter<Message>(......, list) {
void populateView(View view, Message message, int position) {
// the first message was loaded
hideSpinner();
}
});
list.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// the initial data is loaded (even if there was none)
hideSpinner();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "onCancelled", databaseError.toException());
}
});