Tim The Learner
Tim The Learner

Reputation: 75

How to hide app layout until postexecute

Ok I'm executing two async tasks as soon as I open my app. Currently have a Progress dialog but you can still see the layout in the background. So the obvious answer would be to not setContentView(R.layout.activity_main); until the progress dialog is dismissed. But I can't do that as my first async task assigns a video into a view In its post execute and this throws a null pointer exception if the layout has not been set earlier.

   protected void onPostExecute(Void result) {
        //video is a string file created by doinbackground
        card = (VideoView) findViewById(R.id.video);
        card.setVideoPath(video);



        //Video Loop
        card.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });
        card.start();



    }

Upvotes: 0

Views: 41

Answers (1)

Vidya Sagar
Vidya Sagar

Reputation: 180

Inside the layout inside the code and use setVisibity() For example you have to hide a linear layout with id myLayout 1) Set the id in layout xml

android:id="@+id/mylayout"

2)Now under OnCreate method in your code

LinearLayout linearLayout = (LinearLayout) findViewbyId(R.id.mylayout);
linearLayout.setVisibility(View.INVISIBLE)

3) user postExecute method

linearLayout.setVisibility(View.VISIBLE)

Upvotes: 1

Related Questions