Say I add a header view to my list view using the typical method like so:
View header = getLayoutInflater().inflate(R.layout.list_header, null);
TextView headerText = (TextView) header.findViewById(R.id.my_textview);
headerText.setText("This is my header!");
myListView.addHeaderView(header);
myListView.setAdapter(adapter);
Then, later I need to alter the text of the header textview...
TextView headerText = (TextView) findViewById(R.id.my_textview);
headerText.setText("new header text!");
This doesn't appear to work, since the way I originally attached the header to the list was by inflating it...
How do I change the text?
You should simply store the reference to headerText that you used originally. Then call setText
on it later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With