I’m using a ListView with a custom adapter to receive a JSON response and put it into a nice list – works great.
I’m now testing various exceptions and error handling and am catching errors received from my web API within the Android app. This all works great, handles well – but for the life of me I can’t work out how to change the ’empty view’ of a ListView once it has been set once.
It’s within a fragment, if that makes any difference – but the ProgressBar and ListView are defined in an XML layout which is inflated in the Fragment. I have a TextView also inside there which contains some error text – I want to know how to switch the ProgressBar out for the TextView onError()!
Edit: Currently the ListView uses the ProgressBar as the empty view – I want to know how to later change this to another view – XML defined or programmatic.
The UI thread is not being locked as all API calls are carried out on an AsyncTask, so that’s not the issue.
ListView.removeAllViews() caused a fairly imminent crash.
Apologies if this is trivial…
You could define the empty view to be a FrameLayout and put whatever you want the empty state be inside that view and change it the way you’d change contents of any other view.