I have an AsyncTask
running. I have a TextView
that I mimic the message a Toast
initially produces.
I want to clear the TextView
upon success in OnPostExecute
but it not doing so. The task complete Toast
works fine. How do I set the TextView
in the OnPostExecute
to blank? The user is still on the display screen where the TextView
is.
Code is as follows for an error condition:
@Override
protected void onPostExecute(Void result)
{ FetchingImage=0;
if(webLoadError>0)
{
TextView text = (TextView) findViewById(R.id.textView2);
String temp=" ";
text.setText(temp);
Toast.makeText(getApplicationContext(), "Image not available from the internet.\nDefault or last image loaded.\nTry again later.",Toast.LENGTH_LONG).show();
}
}
Try something like:
EDIT:
try making a variable outside the
onCreate
likeTextView text;
and then inside theonCreate
put:text = (TextView) findViewById(R.id.textView2);
and then just put
text.setText("");
inside theonPostExecute
method.See if that works.
I know this thread is old, but I think I found the solution (at least it worked for me), perhaps it help others:
I had a view with 3 textviews with default values receiving values from a webservices from "doInBackground" method of a AsyncTask and later changing the text in them on "onPostExecute" method. The issue was that only one of the three textviews was showing the new text from the ws in the first execution of code (it's a simple application implementing the Zxing barcode reader reading a barcode from a product and obtaining the price from a webserver, anyway), the next executions (after the app is opened) was updating the three textviews normally.
So I noticed that the only textview that was updating its value in the first execution had its parameter "android:textIsSelectable" = true, the other two was false. Bingo, changing this parameter to true in the other 2 textviews solved the issue.