ImageView always null by fragment

0

I want to change the fragment settings in the app and I want to start with the image of the user that is the box below.

on the onCreate

    mDatabase = FirebaseDatabase.getInstance().getReference().child( "Users" ).child( uiD );

    mDatabase.addValueEventListener( new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            users = dataSnapshot.getValue( User.class );

            url=users.getAvatar();

            url();
        }


        @Override
        public void onCancelled(final DatabaseError databaseError) {
        }
    } );

and then the method where imageview always gives me null. Comment that all this I do in the main activity and not in the Fragment. This same code works for me in another activity so I guess I'll need something for the fragment theme

public void url(){
    if(imageview!=null){
        Glide.with(this)
                .load(url)
                .into(imageview);  
    }
    Toast.makeText( context, "ImagenSettings NULL", Toast.LENGTH_SHORT ).show();
    }

    
asked by lujan 09.06.2018 в 20:37
source

1 answer

0

In the end I came up with the solution, I was simply declaring everything in the fragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View vistas=inflater.inflate( R.layout.fragment_settings, container, false );
    imagephotosettings=vistas.findViewById( R.id.photoSettings );
    nameUser=vistas.findViewById( R.id.buttonUser);

    auth = FirebaseAuth.getInstance();
    user = auth.getCurrentUser();

    DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child( "Users" ).child( user.getUid() );

    mDatabase.addValueEventListener( new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {


            users = dataSnapshot.getValue( User.class );

            url=users.getAvatar();

            nameUser.setText(user.getDisplayName());

            url();//foto evento
        }


        @Override
        public void onCancelled(final DatabaseError databaseError) {
        }
    } );




    return vistas;

}

public void url(){
    if(imagephotosettings!=null){
        Glide.with(this)
                .load(url)
                .into(imagephotosettings);
    }
    //Toast.makeText( , "ImagenSettings NULL", Toast.LENGTH_SHORT ).show();
}
    
answered by 10.06.2018 в 12:41