Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:29:12+00:00 2026-06-18T11:29:12+00:00

Is there a way I can embed a loading progress indicator in a ListActivity

  • 0

Is there a way I can embed a loading progress indicator in a ListActivity or Fragment the same way that I can call setListShown() in a ListFragment? I can use a loading dialog but I would prefer to keep things consistent as I am already using setListShown() in other ListFragments.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:29:13+00:00Added an answer on June 18, 2026 at 11:29 am

    I accomplished this by writing a wrapper for the fragment class similar to ListFragment.

    public class AsyncFragment extends Fragment {
    
    static final int INTERNAL_PROGRESS_CONTAINER_ID = 0x00ff0001;
    static final int INTERNAL_CONTENT_CONTAINER_ID = 0x00ff0002;
    
    View mProgressContainer;
    View mContentContainer;
    boolean mContentShown = true;
    
    public AsyncFragment() {}
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final Context context = getActivity();
    
        FrameLayout root = new FrameLayout(context);
    
        // ------------------------------------------------------------------
    
        LinearLayout pframe = new LinearLayout(context);
        pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
        pframe.setOrientation(LinearLayout.VERTICAL);
        pframe.setVisibility(View.GONE);
        pframe.setGravity(Gravity.CENTER);
    
        ProgressBar progress = new ProgressBar(context, null,
                android.R.attr.progressBarStyleLarge);
        pframe.addView(progress, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    
        root.addView(pframe, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    
        // ------------------------------------------------------------------
    
        FrameLayout lframe = new FrameLayout(context);
        lframe.setId(INTERNAL_CONTENT_CONTAINER_ID);
    
        root.addView(lframe, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    
        // ------------------------------------------------------------------
    
        root.setLayoutParams(new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    
        return root;
    }
    
    public void setView(View v) {
    
        FrameLayout lframe = (FrameLayout) getView().findViewById(INTERNAL_CONTENT_CONTAINER_ID);
        lframe.addView(v, new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    
    }
    
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mProgressContainer = getView().findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
        mContentContainer = getView().findViewById(INTERNAL_CONTENT_CONTAINER_ID);
        setContentShown(false, false);
    }
    
    @Override
    public void onDestroyView() {
        mContentShown = false;
        mProgressContainer = mContentContainer = null;
        super.onDestroyView();
    }
    
    
    public void setContentShown(boolean shown) {
        setContentShown(shown, true);
    }
    
    public void setContentShownNoAnimation(boolean shown) {
        setContentShown(shown, false);
    }
    
    private void setContentShown(boolean shown, boolean animate) {
    
        mProgressContainer = getView().findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
        mContentContainer = getView().findViewById(INTERNAL_CONTENT_CONTAINER_ID);
    
        if (mContentShown == shown) {
            return;
        }
        mContentShown = shown;
        if (shown) {
            if (animate) {
                mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_out));
                mContentContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_in));
            } else {
                mProgressContainer.clearAnimation();
                mContentContainer.clearAnimation();
            }
            mProgressContainer.setVisibility(View.GONE);
            mContentContainer.setVisibility(View.VISIBLE);
        } else {
            if (animate) {
                mProgressContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_in));
                mContentContainer.startAnimation(AnimationUtils.loadAnimation(
                        getActivity(), android.R.anim.fade_out));
            } else {
                mProgressContainer.clearAnimation();
                mContentContainer.clearAnimation();
            }
            mProgressContainer.setVisibility(View.VISIBLE);
            mContentContainer.setVisibility(View.GONE);
        }
    }
    

    I use this for fragments that I’m populating asynchronously. To use it, do not override onCreateView(). Instead, inflate your view in onStart() and call setView() with it. The fragment will start with a loading spinner. Call setContentShow(true) after you are done populating your view to remove the loading animation and show your content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can embed a .exe file in a .pdf
I was wondering if there is a way that I can embed webkit or
Is there way that I can read the file from remote server using fopen
Is there any way I can set a formatter on models that will convert
Is there a way I can use one category to stylize all of my
Is there any way I can use JPA or hibernate annotations to specify the
Is there any way I can embed the images within my exe (as resource?)
I currently make my website using iWeb. Is there a way that I can
Is there a way (using html/jquery) I can embed radio buttons in the options
Possible Duplicate: Is there a way to embed a browser in Java? How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.