I tried to change a value of a ListView adapter using a thread, but it throws an exception that is CalledFromWrongThreadException
can anyone call a thread that changes a value of any View element?
here is my code:
new Thread(new Runnable(){
public void run()
{
ap=(ArrayList<Application>) getBoughtApps(android_id);
adapter1 = new MyCustomAdapter(ap);
listView = ( ListView ) MainActivity.this.findViewById(R.id.listview);
changeAdapter();
}
}).start();
First Option :
use runOnUiThread for Updating UI from Non – Ui Thread. change your code as:
Second Option :
You can use AsyncTask instead of a Thread for making Network Operations or if application require to Update Ui from Background. you can change your current code using
AsyncTaskas :and to start
AsyncTaskput this line where you are starting Thread: