我想在Firebase中寻找列表时在屏幕上显示进度条。我怎样才能做到这一点?
现在的代码不会显示进度条。如果你能帮助我,谢谢你。
@Override
protected void onResume() {
super.onResume();
openProgressBar();
callConnection();
mDatabaseReference.child("bakeries").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getChildrenCount() > 0) {
closeProgressBar();
adapter = new FirebaseRecyclerAdapter<Bakery, BakeryViewHolder>(
Bakery.class,
R.layout.card_bakery,
BakeryViewHolder.class,
//referencing the node where we want the database to store the data from our Object
mDatabaseReference.child("bakeries").getRef()
) {
@Override
protected void populateViewHolder(BakeryViewHolder viewHolder, final Bakery model, final int position) {
if (tvNoBakeries.getVisibility() == View.VISIBLE) {
tvNoBakeries.setVisibility(View.GONE);
}
if (icBakery.getVisibility() == View.VISIBLE) {
icBakery.setVisibility(View.GONE);
}
viewHolder.tvBakeryName.setText(model.getFantasyName());
viewHolder.tvPhone.setText(model.getFone());
viewHolder.tvDistrict.setText(model.getAdress().getDistrict());
distance = GeoLocation.distanceCalculate(userLatitude, userLongitude,
model.getAdress().getLatitude(), model.getAdress().getLongitude());
viewHolder.tvDistance.setText(String.valueOf(distance));
//Picasso.with(MainActivity.this).load(model.getMoviePoster()).into(viewHolder.ivMoviePoster);
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.w(TAG, "You clicked on " + model.getId());
bakeryID = model.getId();
String name = model.getFantasyName();
params.putString("bakeryID", bakeryID);
params.putString("name", name);
Intent intentProductList = new Intent(BakeryListActivity.this, ProductListActivity.class);
intentProductList.putExtras(params);
startActivity(intentProductList);
}
});
}
};
rvBakery.setAdapter(adapter);
} else {
tvNoBakeries.setVisibility(View.VISIBLE);
icBakery.setVisibility(View.VISIBLE);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "getUser:onCancelled", databaseError.toException());
}
});
}
调用进度条活动Common Activity
protected void openProgressBar(){
progressBar.setVisibility( View.VISIBLE );
}
protected void closeProgressBar(){
progressBar.setVisibility( View.GONE );
}