Question

I'm beginner in andorid. So my problem has probably simple solution. I want to create overlay of activity with loading message/image. Activity do few parallel async tasks to load content from web server and I want to show it after all async tasks is finished and simultaneously I need to work with the view of activity (add loaded content) and action bar should be visible all the time.

I tried few ways with no success.

  1. Progress dialog - activity view is visible under dialog or all is hidden including action bar.
  2. ViewSwitcher - I get NullPointException when I try to work with view, because second view isn't probably accessible.
  3. Element that overlay whole activity - I don't want to duplicate this in all my acitivity layouts.

Is there any other way how to achieve desired effect? Thank you for any help.

Was it helpful?

Solution

Create a fragment with the overlay, then attach it to your activity like this:

FragmentManager fragmentManager = getFragmentManager();
beginTransaction().add(new MyFragment(), MyFragment.class.getCanonicalName()).commit();

When you're done loading, do

fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().remove(myFragment).commit();

This you will have to do in every activity though, but the actual code for showing the overlay, probably fading it in and out, etc., could be nicely encapsulated by your fragment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top