Why does this not change my TextView's text ? I have a TextView
who's text I try to modify from a view.post method. What am I doing wrong here ?
mTextView = (TextView)findViewById(R.id.text_view);
new Thread(new Runnable() {
@Override
public void run() {
mTextView.post(new Runnable(){
@Override
public void run() {
mTextView.setText("A change in text, thank you very much");
}
});
}
}).start();
This runs in the Activity's onCreate() method. However, if I define a handler and pass the Runnable to the handler the TextView is modified.
Edit: The code I have here is based on the example:
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
final Bitmap bitmap =
loadImageFromNetwork("http://example.com/image.png");
mImageView.post(new Runnable() {
public void run() {
mImageView.setImageBitmap(bitmap);
}
});
}
}).start();
}
at http://developer.android.com/guide/components/processes-and-threads.html
Edit 2:
Now I am totally confused. When I run the same code from an onClickListener attached to a Button in my Activity, the TextView's text is indeed manipulated. Why did this not happen in the onCreate
method ?