Thursday, November 26, 2015

Android updating UI from network thread

When updating the UI after a network operation, it needs to be on a main UI thread. This can be done in android by using the runOnUIThread method

runOnUiThread(new Runnable() {
        @Override
        public void run() {
            View baseView = accessory.getViewReference();
            ProgressBar pg = (ProgressBar)baseView.findViewById(R.id.progressBar);
            if(pg != null) {
                progressBar.setVisibility(View.GONE);
            }
        }
    });

references:

No comments:

Post a Comment