Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to change header/footer view elements for existing ListView?

Tags:

java

android

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?

like image 952
Jake Wilson Avatar asked Oct 25 '11 18:10

Jake Wilson


1 Answers

You should simply store the reference to headerText that you used originally. Then call setText on it later.

like image 103
skynet Avatar answered Oct 18 '22 07:10

skynet