I have a custom List which I want to refresh when a action bar button is clicked. This List is within a Fragment.
I want to show a ProgressBar until the List is refreshed.
Currently Iam doing this:-
private class RefreshList extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if(refDialog!=null)
{
refDialog.dismiss();
}
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
if(refDialog!=null)
{
refDialog =null;
}
refDialog = WaitProgressFragment.newInstance();
refDialog.show(getFragmentManager(), "Wait");
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
//stagAdaper.notifyDataSetChanged();
itemsAdapter.notifyDataSetChanged();
return null;
}
}
But I get this error
Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
How can I refresh the List while showing the progress dialog?