2

I am using the following code to animate a loading circle inside the custom AlertDialog:

    public static void create_custom_progress_dialog(Activity activity, String message){
            Context mContext = activity;
            AlertDialog.Builder builder;
            AlertDialog custom_progress_dialog;         

            LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.myprogressbar, null);

            TextView tv_message = (TextView) layout.findViewById(R.id.message);
            tv_message.setText("" + message);
            ImageView loading_circle = (ImageView)layout.findViewById(R.id.loading_circle);
            loading_circle.setBackgroundResource(R.anim.progress_anim);

            /////////////My ANIMATION/////////////////
            final AnimationDrawable frameAnimation = (AnimationDrawable)loading_circle.getBackground();
            frameAnimation.setCallback(loading_circle);
            frameAnimation.setVisible(true, true);
            loading_circle.post(new Runnable(){

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    frameAnimation.start();
                }

            });

            builder = new AlertDialog.Builder(mContext);
            builder.setView(layout);
            custom_progress_dialog = builder.create();
            custom_progress_dialog.show();
        }

The image is showing but it is not animating. What am I doing wrong?

Jayson Tamayo
  • 2,741
  • 3
  • 49
  • 76
  • Where do you start the animation? – Warpzit Aug 28 '12 at 11:42
  • Noticed the line `loading_circle.post..`. I assume this will start when I called the method. – Jayson Tamayo Aug 28 '12 at 11:44
  • Could you try to start the animation somewhere else? Make a button that starts it or something similar, or just start it after show(); – Warpzit Aug 28 '12 at 11:50
  • I don't know the answer for this question. But if you look into this thread http://stackoverflow.com/questions/9768706/why-is-posting-cancelled-a-runnable-on-a-view-and-handler-result-in-different It says that the post/removecallback won't get called until view is completely attached to the window. So i suggest to try posting with a delay or may be after draw using Gloaballayoutlistner – manjusg Aug 28 '12 at 11:54
  • I have tried putting `loading_circle.post..` after `custom_progress_dialog.show` but it is still not animating. – Jayson Tamayo Aug 28 '12 at 12:03
  • could you try not posting but just calling frameAnimation.start() after dialog.show? – Warpzit Aug 28 '12 at 12:24
  • @Warpzit: Inside the method itself? – Jayson Tamayo Aug 28 '12 at 12:26
  • tried to call `frameAnimation.start();` after `dialog.show`. Not yet working.. – Jayson Tamayo Aug 28 '12 at 12:31
  • I'm sorry I don't have more experience with animation inside dialogs... My last and best advice to you would be to try out dialogfragments. They do wonders. – Warpzit Aug 28 '12 at 12:37

0 Answers0