I have this code which retrieves the information I need from the firebase database:
private void getname(){
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
Query lastQuery = ref.child("ride_info").orderByKey().limitToLast(1);
lastQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()){
String value0_float = ds.child("pickup").child("name").getValue(String.class);
pickupName = String.valueOf(value0_float);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
and i have this:
public String getPickupName() {
getname();
String s = String.valueOf(pickupName);
return s;
}
All of the above code is in the RideObject
class.
This is the code there is in CardRequestAdapter
Class to display the String in the textview mPickupName
:
public View getView(int position, View convertView, ViewGroup parent){
RideObject card_item = getItem(position);
if (convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item__card_request, parent, false);
}
TextView mDistance = convertView.findViewById(R.id.distance);
TextView mTime = convertView.findViewById(R.id.time);
CircularProgressBar mProgressBar = convertView.findViewById(R.id.circularProgressBar);
mDistance.setText(card_item.getPickupName());
mTime.setText(card_item.getCalculatedTime() + " min");
final Handler ha=new Handler();
ha.postDelayed(new Runnable() {
@Override
public void run() {
//call function
card_item.setTimePassed(card_item.getTimePassed() + (float)0.5);
mProgressBar.setProgress(card_item.getTimePassed());
if(card_item.getTimePassed() > 100){
items.remove(card_item);
notifyDataSetChanged();
}
ha.postDelayed(this, 50);
}
}, 50);
return convertView;
}
}
The problem I have is that I cannot get the name I got from the Firebase database. Why is nothing displayed in the text view?