时间后显示按钮(处理程序?)

时间:2014-08-26 10:30:43

标签: java android button count handler

我正在开发一个小应用程序,其想法是用户在15秒内点击一个按钮,其中有textview计算他执行的点击次数。现在我想添加一个重启按钮,但我希​​望在15秒后显示它。你们有任何想法怎么做吗?这是我的代码:

  final TextView textic = (TextView) findViewById(R.id.textView2);
    Typeface fac=Typeface.createFromAsset(getAssets(),"fonts/fipps.otf");
    textic.setTypeface(fac);
        final int oldscore = getSharedPreferences("myPrefs", MODE_PRIVATE).getInt("highscore", 0);


        count = new CountDownTimer(15000, 1000) { // MOVED UP
            public void onTick(long millisUntilFinished) {
                int seconds = (int) ((millisUntilFinished / 1000));
                textic.setText("Time Left: " + millisUntilFinished / 1000);

            }

            public void onFinish() {
                String message;
                textic.setText("Time's Up!");
                buttonCount.setEnabled(false);
                if (clicks > oldscore) {
                    getSharedPreferences("myPrefs", MODE_PRIVATE).edit().putInt("highscore", clicks).commit();

                }
            }
        };
        final TextView textView = (TextView) findViewById(R.id.clicks);
    Typeface face=Typeface.createFromAsset(getAssets(),"fonts/fipps.otf");
    textView.setTypeface(face);
    buttonCount = (ImageButton) findViewById(R.id.button);
        buttonCount.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                clicks++;
                textView.setText("" + clicks);
                TextView textVie = (TextView) findViewById(R.id.topScoreView);
                Typeface fa=Typeface.createFromAsset(getAssets(),"fonts/fipps.otf");
                textVie.setTypeface(fa);
                textVie.setText("Best: " + oldscore);

                if(!started){
                    count.start(); // START COUNTDOWN TIMER
                    started = true;
                    timerProcessing = true;

                }

            }
        });

    }

}

有人可以帮助我,我该怎么办?

2 个答案:

答案 0 :(得分:0)

这是我的代码。我用这个来隐藏5秒后的布局,使用它。希望这会对你有所帮助

private void HideLayout()
{
    swiper=(RelativeLayout)findViewById(R.id.llSwiper);
    header=(LinearLayout)findViewById(R.id.llHeader);
    swiper.postDelayed(new Runnable() 
    {
        public void run() 
        {
            if(!swiper.isPressed())
            {
                swiper.setVisibility(View.GONE);
            }
            else
            {
                HideLayout();
            }
        }
    }, 5000);
}

答案 1 :(得分:0)

只需在你的布局中添加按钮,就像你的textview一样,并将其设置为不可见。当时间超出时(在onfinish()中)可以看到它。