gpt4 book ai didi

android - 到达时间时计时器开始 Activity

转载 作者:太空狗 更新时间:2023-10-29 16:23:16 25 4
gpt4 key购买 nike

我希望在达到新 Activity 时开始新 Activity ,到目前为止我遇到了一些麻烦。这是我到目前为止所拥有的。我希望你们明白我想做什么。如果有更简单的方法,请告诉我。也许我应该把它放在一个线程中?

 Chrono = (Chronometer) findViewById(R.id.chronometer1);
Chrono.start();
while (!(Chrono.equals(chronoText))) {
chronoText = Chrono.getText().toString();
if (chronoText.equals("00:30")) {
Intent intent = new Intent(getApplicationContext(),
Hw3Activity.class);
startActivity(intent);
}

}

我的整个代码:

    public class Next extends Activity {
Button returned;
Button click;
Button search;
EditText clicksearch;
TextView counted;
int counter;
int answer;
Chronometer Chrono;
CharSequence chronoText;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screentwo);
// waiter = new Waiter(60 * 1000); // 1 min
// waiter.start();

Chrono = (Chronometer) findViewById(R.id.chronometer1);
Chrono.start();
Log.d("Ebz", "uhh");
returned = (Button) findViewById(R.id.returned);
click = (Button) findViewById(R.id.click);
search = (Button) findViewById(R.id.search);
clicksearch = (EditText) findViewById(R.id.clicksearch);
counted = (TextView) findViewById(R.id.counted);
chronometer(); // its called here
returned.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter = 0;
Intent intent = new Intent(getBaseContext(), Hw3Activity.class);
answer = intent.getIntExtra("meaningOfLife", -1);

Intent i = getIntent();
i.putExtra("returnInt", answer);
setResult(RESULT_OK, i);
startActivity(intent);

}
});
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
counted.setText(String.valueOf(counter));
Chrono.setBase(SystemClock.elapsedRealtime());

}
});
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, clicksearch.getText()
.toString());
startActivity(intent);
}
});
clicksearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

}
});
}

public void chronometer() {
while (!(Chrono.equals(chronoText))) {
chronoText = Chrono.getText();
Log.d("Ebz", "makes it to chronometer");
counted.setText(String.valueOf(chronoText));
if (chronoText.equals("00:10")) {
Intent intent = new Intent(getApplicationContext(),
Hw3Activity.class);
startActivity(intent);
}

}
}
}

最佳答案

尝试在您的 Activity 上实现 Chronometer.OnChronometerTickListener 并将来自 chronometer() 的代码放在那里(或相关部分)。

public class Next extends Activity
implements Chronometer.OnChronometerTickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {

...

Chrono = (Chronometer) findViewById(R.id.chronometer1);
Chrono.setOnChronometerTickListener(this);
Chrono.start();

...
}

public void onChronometerTick(Chronometer chronometer) {
if ("00:10".equals(chronometer.getText()) {
// Create Intent and start the new Activity here
}
}
}

关于android - 到达时间时计时器开始 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com