Answer the question
In order to leave comments, you need to log in
How to access the text fields in the sidebar header?
I am new to android programming. How do I access these 2 textboxes in the sidebar header of the navigation drawer activity?
It doesn't work in the standard way:
TextView hello;
hello = (TextView) findViewById (R.id.hello);
hello.setText("Hello world!");
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
Answer the question
In order to leave comments, you need to log in
android
//задаем navigationView
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
//задаем его шапку
View header_nv = navigationView.inflateHeaderView(R.layout.nav_header_main);
//нужный нам элемент
TextView hello = (TextView) header_nv.findViewById(R.id.hello);
// и собственно изменяем его
hello.setText("Hello world!");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question