0
我有Firebase用戶和他們所做的帖子。我想從帖子中獲取帖子圖片網址,下載它們並在gridview中顯示它們。如何在GridView中顯示Firebase照片?
這是我的代碼:
public class Profile extends Fragment {
private CircleImageView mprofilePic;
private TextView mUsername, mBio;
private GridView mGridView;
private Uri mImageUri = null;
private FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
private StorageReference mStorageImage;
private DatabaseReference mdatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users");
private FirebaseAuth mAuth;
private FirebaseUser mCurrentUser;
private DatabaseReference userposts;
private static final int GALLERY_REQUEST = 1;
public static Profile newInstance() {
return new Profile();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View profileView = inflater.inflate(R.layout.fragment_profile, container, false);
mAuth = FirebaseAuth.getInstance();
mCurrentUser = mAuth.getCurrentUser();
userposts = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid()).child("posts");
mprofilePic = (CircleImageView) profileView.findViewById(R.id.profile_picture);
mUsername = (TextView) profileView.findViewById(R.id.profile_username);
mBio = (TextView) profileView.findViewById(R.id.profile_bio);
mGridView = (GridView) profileView.findViewById(R.id.gridview);
mdatabaseUsers.child(firebaseUser.getUid()).child("image")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String imageUrl = dataSnapshot.getValue().toString();
Glide.with(getContext()).load(imageUrl).into(mprofilePic);
//mprofilePic.setImageURI(Uri.parse(imageUrl));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mdatabaseUsers.child(firebaseUser.getUid()).child("Name").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String username = dataSnapshot.getValue().toString();
mUsername.setText(username);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return profileView;
}
}
我需要的是獲得當前用戶,並得到孩子(職位)和兒童(圖像),然後下載它,並把它網格視圖,然後運行到下一個帖子並獲取第二個帖子圖片等等。
有什麼建議嗎?謝謝!