java countdowntimer,弹出窗口中的CountDownTimer

Ohke, so I've updated to this:

final AlertDialog.Builder popup_timer = new AlertDialog.Builder(ScoreNewGame.this);

popup_timer.setTitle("Timer:\t90 sec between games");

CountDownTimer gameTimer = new CountDownTimer(9000, 1000)

{

@Override

public void onTick(long time_remaining)

{

popup_timer.setMessage("Time remaining:\t" + time_remaining);

}

@Override

public void onFinish()

{

}

};

gameTimer.start();

popup_timer.show();

But now I get the following error-

Failure getting entry for 0x010802c9 (t=7 e=713) in package 0 (error -75)

I searched around a bit but can't find any solution. Also, 0x010802c9 doesn't correspond to anything in R.java.

The app doesn't crash though, the popup just doesn't display the countdowntimer like I want

解决方案

I would suggest creating a dialog fragment instead. At that point you can handle the countdown timer in the fragment any which way you want.

Here's an example of a dialog fragment:

public class CountDownDialog extends DialogFragment {

private TextView mCountdownView;

public CountDownDialog(){}

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_countdowntimer_dialog, container);

mCountdownView = (TextView) view.findViewById(R.id.countdownTimer);

return view;

}

@Override

public void onActivityCreated(Bundle savedInstanceState) {

super.onActivityCreated(savedInstanceState);

CountDownTimer gameTimer = new CountDownTimer(10000, 1000) {

@Override

public void onTick(long l) {

mCountdownView.setText(""+((int)Math.round(l/1000.0)-1));

}

@Override

public void onFinish() {

dismiss();

}

};

gameTimer.start();

}

}

and here's how you would call it

CountDownDialog countDownDialog = new CountDownDialog();

countDownDialog.show(getSupportFragmentManager(), "fragment_countdownTimer");

I used a pretty simple layout for the fragment to to test it:

android:orientation="horizontal" android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="Countdown:"

android:id="@+id/countdownTitle"

android:layout_marginLeft="@dimen/activity_horizontal_margin" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="9"

android:id="@+id/countdownTimer"

android:layout_marginLeft="8dp" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值