AsyncTask OnPostExecute not updating TextView

后端 未结 2 611
死守一世寂寞
死守一世寂寞 2020-12-19 19:57

I have an AsyncTask running. I have a TextView that I mimic the message a Toast initially produces. I want to clear the TextView

相关标签:
2条回答
  • 2020-12-19 20:09

    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.

    0 讨论(0)
  • 2020-12-19 20:10

    Try something like:

    ((TextView) findViewById(R.id.textView2)).setText("");
    

    EDIT:

    try making a variable outside the onCreate like TextView text; and then inside the onCreate put: text = (TextView) findViewById(R.id.textView2);

    and then just put text.setText(""); inside the onPostExecute method.

    See if that works.

    0 讨论(0)
提交回复
热议问题