So, I have a code:
((Button) findViewById(R.id.run)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
progDialog = ProgressDialog.show(WaggActivity.this,
"", "Loading...", true, true);
new Thread(new Runnable() {
public void run() {
try {
urlTxt.setText(findUrl(String.valueOf(search.getText())));
} catch (Exception e) {
Log.e("MainActivity", e.getMessage());
}
progDialog.dismiss();
}
}).start();
I cannot find a mistake. 🙁
Error is: Only the original thread created a view hierarchy can touch its vews.
In Android you have a UI-Thread, in which is created by your activity. This is the only thread in which you can modify the Views, which in your case is the ProgressDialog.
So you can’t modify it from other threads, you must call it from within your Ui-thread.
You should call :
Activity.runOnUiThread(Runnable)As explained here.;