Im trying to display inside an alert dialog the variable i (succesfully)get from firebase. As i mention in the comment i get nothing. I mean i get the first declaration of the value,which is ""
. What im doing wrong?
EDIT: The variable name is defined at the top of my class as public String name="";
@Override
public void handleResult(Result result) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Scan Result");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
getItemData();
//here im trying to print the 'name' variable from getItemData(), and i get ""
builder.setMessage(name);
AlertDialog alert1 = builder.create();
alert1.show();
}
//here i get the item from firebase
public void getItemData(){
final DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference("Items").child(myResult);
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
name = dataSnapshot.child("itemname").getValue().toString();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(addquantityactivity.this,"there was an error",Toast.LENGTH_SHORT).show();
}
});
}