Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Hooking Up the Model to the View Adding a Refresh Button

Vikzilla III
PLUS
Vikzilla III
Courses Plus Student 4,365 Points

Using runOnUIThread() within toggleRefresh() more clean?

Would implementing runOnUIThread() within the toggleRefresh() helper be more DRY? Because otherwise we have to call runOnUIThread() in multiple places and call our toggleRefresh() within it.

Here's how I'm doing it:

private void toggleRefresh() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mProgressBar.getVisibility() == View.INVISIBLE) {
                mProgressBar.setVisibility(View.VISIBLE);
                mRefreshImageView.setVisibility(View.INVISIBLE);
            }
            else {
                mProgressBar.setVisibility(View.INVISIBLE);
                mRefreshImageView.setVisibility(View.VISIBLE);
            }
        }
    });
}

Or, is there a disadvantage to calling runOnUIThread() when it isn't necessary--such as the first time we call it in getForecast().

Would be very interesting Craig Dennis Ben Jakuben Ben Deitch

Sean Wilson
Sean Wilson
3,791 Points

This is much cleaner! Any ideas yet if there is an issue with this?

Boban Talevski
Boban Talevski
24,793 Points

Interesting question, just adding my comment here in hope that someone could clear it up two years later :)