I am making an app where I can upload images to firebase then retrieve them and view them in a viewpager. The images have a name and an url. In addition to that, I want to be able to write the name of the image in a textbox and display the corresponding image in an imageview.
This is the code I'm working with :
private void findImage(){
final Query query = mDatabaseRef.orderByChild("name").equalTo(EditTextName.getText().toString());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot NamedImage : dataSnapshot.getChildren()) {
//i have tried this first but i don't know what method i should use to get the URI from the datasnapshot.
image.setImageURI(NamedImage.getValue());
//then i have tried this but i can't use "context" here, nor can i apply .getImageUrl to the datasnapshot.
Glide.with(context).load(NamedImage.getImageUrl()).into(image);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
I am new to android studio and java and I haven't studied it before starting this application. Any idea on what I should do please?
I found the solution to my problem :
private void findImage(){
final Query query = mDatabaseRef.orderByChild("name").equalTo(EditTextName.getText().toString());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot NamedImage : dataSnapshot.getChildren()) {
SliderUtils sliderUtils = NamedImage.getValue(SliderUtils.class);
Glide.with(getApplicationContext()).load(sliderUtils.getImageUrl()).into(image);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.