0

我試圖從Firebase中檢索個人資料照片,並使用了片段。如何使用Firebase中的片段檢索個人資料照片?

我是新來的碎片。這裏是我的火力地堡數據庫結構:

database

存儲:

Storage

這裏是我的片段:

public class Profile extends Fragment { 

    private CircleImageView mprofilePic; 
    private TextView mUsername, mDescription, mEditProfile; 
    private ImageButton mSettings; 

    public Profile() { 
     // Required empty public constructor 
    } 

    public static Profile newInstance(int instance) { 
     Bundle args = new Bundle(); 
     args.putInt("argsInstance", instance); 
     Profile profile = new Profile(); 
     profile.setArguments(args); 
     return profile; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View profile = inflater.inflate(R.layout.fragment_profile, container, false); 

     mprofilePic = (CircleImageView) profile.findViewById(R.id.circleImageView_profileimage_profile); 
     mUsername = (TextView) profile.findViewById(R.id.textView_username_profile); 
     mDescription = (TextView)profile.findViewById(R.id.textView_info_profile); 
     mEditProfile = (TextView)profile.findViewById(R.id.textView_editprofile_profile); 
     mSettings = (ImageButton)profile.findViewById(R.id.imageButton_settings_profile); 

     return profile; 
    }   
} 

回答

0
Firebase.setAndroidContext(getActivity()); 
     Firebase ref = new Firebase(FIREBASE_URL); 
     ref.child("users/0THnm4Tt6WNLm62D2lbtNlzTg2t2/image") 
        .addListenerForSingleValueEvent(new ValueEventListener() { 
         @Override 
         public void onDataChange(DataSnapshot dataSnapshot) { 
          if (dataSnapshot.getValue() != null) { 
           String profilePic = ""; 
           profilePic = (String) dataSnapshot.getValue(); 
           // show image in imageview code 
          } 
         } 

         @Override 
         public void onCancelled(FirebaseError firebaseError) { 
         } 
        }); 
相關問題