dawidurusek
dawidurusek

Reputation: 123

How to disable/block onClickListener for few seconds?

I made nice looking splash screen and I want to block onclicklistener for a few seconds cause i've got few animations etc and I want the user see it all.

I've got:

 ostatni.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                starttap.start();

                Intent i = new Intent(Start.this,ActivityMainWallet.class);

                startActivity(i);
            }
        });

EDIT

I've got:

ostatni.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                starttap.start();
                ostatni.setEnabled(false);


            }
        });

        wlot.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                Intent i = new Intent(Start.this,ActivityMainWallet.class);

                startActivity(i);
                ostatni.setEnabled(true);

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

And it doesn't work. Please help me, thanks!

Upvotes: 0

Views: 378

Answers (4)

志威梦
志威梦

Reputation: 136

SystemClock.sleep(2000)will be better.

sleep 2ms, and this method will not block the thread.

Upvotes: 1

Aldi Renaldi Gunawan
Aldi Renaldi Gunawan

Reputation: 510

add this ?

public onCreate(....)
{
     ......
     ......
     ostatni.setOnClickListener(........);
     ostatni.setEnabled(false);
}

 @Override
 public void onAnimationEnd(Animation animation) {
            ostatni.setEnabled(true);
 }

Upvotes: 0

MaxExplode
MaxExplode

Reputation: 2007

You can also use android animation utils to do this

final Animation an = AnimationUtils.loadAnimation(getBaseContext(), R.anim.abc_fade_in);

<your imageviews or any other view>.startAnimation(an);
  an.setAnimationListener(new Animation.AnimationListener() {
    @Override
     public void onAnimationStart(Animation animation) {

     }

     @Override
     public void onAnimationEnd(Animation animation) {
                //start your main activity
     }

     @Override
     public void onAnimationRepeat(Animation animation) {

     }
});

Upvotes: 0

Frank B.
Frank B.

Reputation: 204

You can pause the thread it is running on, the main thread (UI Thread):

Thread.sleep(4000); // freeze the thread for 4 seconds

Source: Java, Pausing Execution

Upvotes: 1

Related Questions