I był przy this do wyświetlania obrazu z Internetem, a zgłasza błąd, jak poniżej:
12/04 13: 45: 05.337: E/Android Runtime (27897) spowodowane przez: Android .view.ViewRootImpl $ CalledFromWrongThreadException: Tylko oryginalny wątek, który utworzył hierarchię widoku, może dotykać jej widoków.
public class Order extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new DownloadFilesTask().execute();
}
private class DownloadFilesTask extends AsyncTask<Void, Void, Void> {
protected void onPostExecute(Void result) {
}
@Override
protected Void doInBackground(Void... params) {
setContentView(R.layout.order);
ImageView imageView = (ImageView)findViewById(R.id.imgView);
imageView.setImageDrawable(createDrawableFromURL("http://savagelook.com/misc/sl_drop2.png"));
return null;
}
}
private Drawable createDrawableFromURL(String urlString) {
Drawable image = null;
try {
URL url = new URL(urlString);
InputStream is = (InputStream)url.getContent();
image = Drawable.createFromStream(is, "src");
} catch (MalformedURLException e) {
image = null;
} catch (IOException e) {
image = null;
}
return image;
}
}
Patrz „Manipulatory nici” http://www.techotopia.com /index.php/A_Basic_Overview_of_Android_Threads_and_Thread_handlers – samosaris
W Mono użyj RunOnUiThread ... RunOnUiThread (() => {_tvMessage.Text = "Ładowanie ...";}); http://mono-for-android.1047100.n5.nabble.com/Can-t-create-handler-inside-thread-sync-problem-why-td5710999.html – samosaris