Obtain control of an IMAGEVIEW CONTROL


I currently have a menu that is a NavigationView . Where this is made up of the header and the body , in the HEADER I have a image , which is the following



        android:layout_marginTop="17dp" />

Now I would like the user to change it so I let him select one of his gallery and I keep that url in a Sql lite database, until here everything is fine, but at the time of wanting to reference the image I thought that with looking for it with your ID

foto_gallery = (ImageView)findViewById(R.id.foto_gallery);

It was going to be enough but I find that looking for it by ID is as if I have a imagenview in my Layout of my class, but it is not like this in a xml that is part of the NaviewView , then how can I refer to that image that is in xml that is part of my menu, I do not know if I made myself understood, thank you.

asked by Bruno Sosa Fast Tag 03.11.2017 в 20:03

1 answer


Use the method navigationView.getHeaderView(int index) to get the reference of the header and then look for the image using findViewById() :

ImageView profile = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.foto_gallery);
answered by 03.11.2017 / 20:10