How to instantiate views from another layout?

0

I have the main layout and the code that controls it, this layout has a Navigation Drawer (the "slider" on the left) and left the layout of Main Header (the top of Navigation Drawer where user information) into another file. I tried instantiating these views for FindViewById of MainActivity thinking it would work because main_header is included in the main layout, but it does not work, I debug the code and I saw that the variables that should have that main_header were receiving null , as if it were not possible to access them from there, how can I instantiate them?

(I'm doing the project in Xamarin Android , but so far the operation seemed the same compared to Java , so if you know how to respond in Java help too.)

    
asked by anonymous 18.11.2017 / 15:32

1 answer

0

If someone needs the answer in the future too: the NavigationView (where you define the main header) has a method called getHeaderView() , after instantiating NavigationView you "save" its header in another view and use it to instantiate.

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View header = navigationView.getHeaderView(0)
TextView text = (TextView) header.findViewById(R.id.textView);
    
25.01.2018 / 20:10