1

I'm trying to set multiple TextView by calling setText on my TextView from my MainActivity.java but I get an error (null object) because (I guess) my setContentView is pointed on R.id.first_layout and one of the TextView is in another layout (let's say R.id.second_layout).

How could I setText on those 2 differents layout in my MainActivity ?

I tried the following code but nothing change when I launch the app :

LayoutInflater inflater = getLayoutInflater();
View navHeaderView = inflater.inflate(R.layout.second_layout, null);

nameTextView = (TextView) 
navHeaderView.findViewById(R.id.nameTextView);
nameTextView.setText("Test")
Yohann L.
  • 1,262
  • 13
  • 27
  • Is `second_layout` the header layout for a `NavigationView` that's in `MainActivity`? – Mike M. Apr 11 '17 at 10:10
  • @MikeM. yes ! I tried to change the info of the header with a setText – Yohann L. Apr 11 '17 at 20:38
  • The header takes a some time to actually load into the `View` hierarchy in recent versions, so you have to do things a little differently. The question linked at the top of the page has the options. – Mike M. Apr 11 '17 at 20:41
  • @MikeM. Great, thank you, I'll take a look at the question linked! – Yohann L. Apr 12 '17 at 14:20

0 Answers0