我有一个扩展片段活动的导航 .

我想做的事

当我打开导航时,我想启动倒数计时器 .

然后当我从导航中访问一个片段时,我想用倒数计时器中的分钟和秒来填充两个文本视图,而当我在这个片段上时,文本视图将使用倒数计时器中的值进行更新 .

我怎么能提供?

非常感谢 :) .

在导航中:

LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.layout.settings_activity, null);

TextView remainedMinTextView = (TextView) v
        .findViewById(R.id.remainedMinTextView);
TextView remainedSecTextView = (TextView) v
        .findViewById(R.id.remainedSecTextView);
Utils.startCountDownTimer(10000, remainedMinTextView, remainedSecTextView);

在utils类中,我创建了倒计时器

public static void startCountDownTimer(final long milis,
    final TextView remainedMinTextView,
    final TextView remainedSecTextView) {

    CountDownTimer countDownTimer = new CountDownTimer(milis, 1000) {

        @Override
        public void onTick(long millisUntilFinished) {
            remainedMinTextView.setText(""
                    + String.format("%d", TimeUnit.MILLISECONDS
                            .toMinutes(millisUntilFinished)));

            remainedSecTextView
                .setText(""
                + String.format(
                "%d",
                TimeUnit.MILLISECONDS
                .toSeconds(millisUntilFinished)
                - TimeUnit.MINUTES
                .toSeconds(TimeUnit.MILLISECONDS
                .toMinutes(millisUntilFinished))));
        }

        @Override
        public void onFinish() {

        }
    }.start();
}

在我有两个文本视图的片段中

@SuppressLint("InflateParams")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    /** Inflating the layout for this fragment **/
    View v = inflater.inflate(R.layout.settings_activity, null);

    // minutes/seconds passed in app
    remainedMinTextView = (TextView) v
            .findViewById(R.id.remainedMinTextView);
    remainedMinTextView.setTypeface(Utils.TypeFace(getActivity()));

    remainedSecTextView = (TextView) v
            .findViewById(R.id.remainedSecTextView);
    remainedMinTextView.setTypeface(Utils.TypeFace(getActivity()));
}

好的,例如我点击5分钟(这里是文本视图更新的地方)

textViewTimer5 = (TextView) v.findViewById(R.id.imageViewTimer5);
textViewTimer5.setTypeface(Utils.TypeFace(getActivity()));

textViewTimer5.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    Utils.startCountDownTimer(300000, remainedMinTextView, remainedSecTextView);
    }
});

如果我从这里调用倒计时它可以工作......但我需要的是当我打开导航并开始倒计时然后我打开包含两个文本视图的片段,用倒计时值来更新 .