Android: Adding a delay to the display of toast?

前端 未结 2 1522
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 04:44

I wish to display a toast if a certain condition is true or false. However I want this toast to delay for two secon

2条回答
  •  猫巷女王i
    2020-12-22 05:31

    Try this..

    Use Handler

                // Handler which will run after 2 seconds.
                new Handler().postDelayed(new Runnable() {
    
                    @Override
                    public void run() {
                          Toast.makeText(MathsGameResults.this,
                                    "Data is successfully uploaded.",
                                    Toast.LENGTH_LONG).show();
                    }
                }, 2000);
    

提交回复
热议问题