I have the following code which should update UI textview on Asynctask:
public class HelloWorldActivity extends Activity
{
private static TextView txtview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtview = (TextView) findViewById(R.id.mainview);
}
private static class SimpleTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... res) {
try {
Thread.sleep(1500);
} catch(InterruptedException exception) {
Thread.currentThread().interrupt();
}
return null;
}
@Override
protected void onPostExecute(Void params) {
txtview.setText("Hola Mundo");
}
}
}
Particularly I'm triying to change Hello World
to Hola Mundo
after 1,5 seconds passed. The problem is that while running the app the text still is Hello World
and doesn't change. I get no error of any sort. I have even set txtview
value outside onCreate
method to avoid any access problems (or so I think).
If after txtview = (TextView) findViewById(R.id.mainview);
I do txtview.setText("Hola Mundo");
then it works flawlessly.
What could be the problem?