在eclipe android app中需要帮助! [英] need help in eclipe android app!!!

查看:72
本文介绍了在eclipe android app中需要帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码和东西的完全noob但我想制作我自己的应用程序,这是一个重复的倒计时和用户选择的时间,倒计时完成后,即使手机是特定的声音和振动出现锁定。所以我发现了两个示例项目,一个是关于时间选择器的秒,另一个是倒数计时器,所以我把它们放在一个项目中,但我的问题是如何让时间选择器设置的时间用于倒数计时器?请帮帮我吧!抱歉,如果这是一个愚蠢的问题,但我真的需要制作该应用程序。



i'm completely noob in coding and stuff but i wanted to make my own app which is a repeated countdown and the time is chosen by user and when the countdown is done a specific sound and vibration comes up even if the phone is locked. so i found two example projects one is about time picker with seconds and another one which is a countdown timer, and so i put them together in one project but my problem here is how do i make the time set by the time picker be used in the countdown timer?? please help me out here! sorry if it's a stupid question but i really need to make that app.

import java.util.Calendar;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import com.ikovac.timepickerwithseconds.view.MyTimePickerDialog;
import com.ikovac.timepickerwithseconds.view.TimePicker;

public class MainActivity extends Activity implements OnClickListener {
private static final String tag = "Main";
private MalibuCountDownTimer countDownTimer;
private long timeElapsed;
private boolean timerHasStarted = false;
private Button startB;
private TextView text;
private TextView timeElapsedView;
private TextView time;
private final long startTime = 50000;
private final long interval = 1000;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    startB = (Button) this.findViewById(R.id.button);
    startB.setOnClickListener(this);

    text = (TextView) this.findViewById(R.id.timer);
    timeElapsedView = (TextView) this.findViewById(R.id.timeElapsed);
    countDownTimer = new MalibuCountDownTimer(startTime, interval);
    text.setText(text.getText() + String.valueOf(startTime));
    updateViews();
}

private void updateViews(){
    time = (TextView) findViewById(R.id.time);
}


public void onClick(View v)
    {
        if (!timerHasStarted)
            {
                countDownTimer.start();
                timerHasStarted = true;
                startB.setText("Start");
            }
        else
            {

                countDownTimer.cancel();
                timerHasStarted = false;
                startB.setText("RESET");
            }
    }

public void showPicker(View v){
    Calendar now = Calendar.getInstance();
    MyTimePickerDialog mTimePicker = new MyTimePickerDialog(this, new MyTimePickerDialog.OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int minute, int minute1, int seconds) {
            // TODO Auto-generated method stub
            time.setText(getString(R.string.time) + String.format("%02d", minute1) + 
                    ":" + String.format("%02d", seconds));              
        }
    }, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND), true);
    mTimePicker.show();     
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public class MalibuCountDownTimer extends CountDownTimer
{

    public MalibuCountDownTimer(long startTime, long interval)
        {
            super(startTime, interval);
        }

    @Override
    public void onFinish()
        {
            text.setText("Time's up!");
            timeElapsedView.setText("Time Elapsed: " + String.valueOf(startTime));
        }

    @Override
    public void onTick(long millisUntilFinished)
        {
            text.setText("Time remain:" + millisUntilFinished);
            timeElapsed = startTime - millisUntilFinished;
            timeElapsedView.setText("Time Elapsed: " + String.valueOf(timeElapsed));
        }
}

}

推荐答案

这篇关于在eclipe android app中需要帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆