Update ListView footer

737 Views Asked by At

I've a ListView with a footer View that contains a TextView that can be changed dynamically according to the language selected.
When I select a different language I update my ListView items:

mBaseAdapter.updateItems(items);

BaseAdapter:

public void updateItems(List<Map.Entry<Integer, String>> items) {
        mItemsResIdList = new ArrayList<>(items);
        notifyDataSetChanged();
}

And to update my footer I was doing this:

mListViewFooter.invalidate();

This didn't work, the text didn't change. However, it works if I replace the invalidate(); with:

((TextView)mListViewFooter.findViewById(R.id.myTextView)).setText(R.string.myCopy);

Note: my ListView elements are TextViews that are translated according to the language selected and they can also increase or decrease in number. My footer never changes, I just want a View update so that the text gets translated (the correct value-(lang)/strings.xml gets picked).

My question is, why does the first approach doesn't work? The only explanation I can think of is that the invalidate(); does not invoke setText() again, it only redraws the View. It worked with the ListView because the adapter calls getView() again where the TextViews are populated again. Is this assumption correct?

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

The behavior is expected only. Calling invalidate() of any view will just re-draw the content what is there already, it will not update unless the change is in the canvas.
When you change the language, the footerView is not notified, so that it can change the content. So when you attempt to get the content from strings.xml, you are getting the correct language. Setting the text again, is the way to do it.