public class Main2Activity extends AppCompatActivity {
String value; //how to make its value avliable in end of program
//i want to use its value after ondatachange to picasso
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
// Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("url");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Toast.makeText(getApplicationContext(), "Hello JavatpointF", Toast.LENGTH_SHORT).show();
}
});
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
ImageView imageView = (ImageView) findViewById(R.id.image1);
Picasso.with(this).load(value).into(imageView);
//i did not getting the value here it showing blank toast
}
}
答案 0 :(得分:2)
替换String value = dataSnapshot.getValue(String.class);
截至value = dataSnapshot.getValue(String.class);