Take the 2-minute tour ×

I'm working on a game using AndEngine, and I need to show the users the list of his Facebook friends. I've created my custom Adatper for the ListView and after the loading finishes everything works great. I have a problem with the loading part it self.

The ListView is inside a custom dialog, So inside this dialog, I'm running an AsyncTask to fetch the friends' info, in that AsyncTask I have a ProgressDialog. The problem is, the ProgressDialog shows up behind the dialog that contains the to-be list (which while loading, is just the title). I can see the ProgressDialog "peeking" behind that dialog.. Any Ideas?

Here's some code:


private ProgressDialog dialog;

//Constructor of the AsyncTask
public FriendsLoader(Context context) {
    dialog = new ProgressDialog(context);
    dialog.setMessage("Please wait..\nLoading Friends List.");

protected void onPreExecute() {
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    dialog.setView(inflater.inflate(R.layout.loading, null));
    dialog.setMessage("Please wait..\nLoading friends.");

protected void onPostExecute(ArrayList<HashMap<String, Object>> data) {
    if (dialog.isShowing()) {
    MyAdapter myAdapter = new MyAdapter(context, data);
    listView = (ListView) findViewById(R.id.list);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
            String id = (String) listView.getItemAtPosition(myItemInt);
share|improve this question
I am sorry, but when I am reading problems like "Android ProgressDialog inside another dialog" my brain began to boil. I think you are generating evil things. My advice: try to think correct, and do things the way they must be done. –  Dmytro Danylyk Nov 3 '12 at 23:15
at first I wanted to do this using AndEngine alone, but couldn't find how.. so I'm going with this. It's really not that complicated. A dialog with a list, should have loading indicator while loading data.. –  La bla bla Nov 3 '12 at 23:17
Why don't you use a ProgressBar, or something like that, as the content of your Dialog ? Then when loading is finished just change its content and replace it with your ListView. –  Flawyte Nov 5 '12 at 23:07
add comment

2 Answers

up vote 1 down vote accepted

Opening a dialog from another dialog is not the best idea, especially if one of them is a progress dialog (try to rotate the screen..).

I suggest a better approach:

The friends dialog will have 2 views: ListView and a ProgressBar. The ListView will be invisible when you load the data, and the ProgressBar will be visible at the time. When you'll finish loading the data, just switch the visibility between those 2 views.

For a smoother transition between those views, you can use ViewAnimator, which takes care of the visibility modes and even allows you to add an effect to the transition (e.g. fade, slide etc.). It's very simple to use and there are lots of examples online.

Best of luck!

share|improve this answer
Great answer. It works even better than I expected! Thanks. Will give the bounty when it will allow me (13 hours from now) –  La bla bla Nov 6 '12 at 9:33
add comment

Use Activity as a dialog by setting style(in manifest). and than you can use Progress Dialog inside that activity

share|improve this answer
add comment

Your Answer


