I am calling a webservice through asynctask, to call the webservice i am calling one method named makeRequest() in doInBackground(), I am getting the response in another methods success(), In success method i am updating the listview
But i am getting error like
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views."
Here Im adding my code.Im calling synctask from activity
new MyTask(this,urlAsString,sp).execute();
here is the Asynctask class
class MyTask extends AsyncTask<Void, Void, Void> {
ProgressDialog progress;
String url;
SharedPreferences sp;
HomepageH2desk c;
public MyTask(HomepageH2desk context,String url,SharedPreferences sp) {
this.c = context;
this.url = url;
this.sp = sp;
progress = new ProgressDialog(this.c);
progress.setMessage("Loading...");
}
public void onPreExecute() {
progress.show();
}
public Void doInBackground(Void... unused) {
c.getTickets(url,sp);
return null;
//progress.setMessage("Loading...");
}
public void onPostExecute(Void unused) {
progress.dismiss();
}
}
Here im getting webservice response
public void success(Object result) {
list = (ArrayList<Map<String, String>>) result;
this.adapter.setList(list);
this.adapter.notifyDataSetChanged();
}
listview is not getting updated and showing error
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Help me to solve this problem…
You should update your List like this.