Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handler postDelayed not able to update UI

Hello guys I'm trying to update the UI after a short delay and for this I'm using handler's postdelayed method. The following code initially sets my textview text to "Processing" and the code that's included in the the handler's runnable gets executed but doesn't update the UI? Please note that this is done in a Fragment

TextView progressText=(TextView)parent.findViewById(R.id.inProgressText);
progressText.setText("Processing");

getActivity().getMainLooper()).postDelayed(new Runnable() {
    @Override
    public void run() {
        TextView progressText=(TextView)parent.findViewById(R.id.inProgressText);
        progressText.setText("Request completed");              
    }
}, 3000);

Thanks for your help

like image 216
Adi Avatar asked Jul 11 '26 12:07

Adi


1 Answers

Change

getActivity().getMainLooper()).postDelayed(new Runnable()

to:

final Handler handler = new Handler();

Then

handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        final TextView progressText=(TextView)findViewById(R.id.inProgressText);
        progressText.setText("Request completed");              
    }
}, 3000);
like image 164
Melquiades Avatar answered Jul 14 '26 00:07

Melquiades



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!