如何解决需要从电话中获取当前时间和日期,并将其发送到服务器
| 我可以显示当前时间,但不会显示日期。我还想按下按钮并确认其被单击,并且吐司显示时间/日期的信息,然后立即返回MainActivity。 ClockInActivity.java import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ClockinActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clockin);
Thread myThread = null;
Runnable runnable = new CountDownRunner();
myThread= new Thread(runnable);
myThread.start();
}
public void doWork() {
runOnUiThread(new Runnable() {
public void run() {
try{
TextView txtCurrentTime= (TextView)findViewById(R.id.lbltime);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = hours + \":\"+ minutes + \":\"+ seconds;
txtCurrentTime.setText(curTime);
TextView txtDateTime= (TextView)findViewById(R.id.Date);
final Calendar c = Calendar.getInstance();
int Year = c.get(Calendar.YEAR);
int Month = c.get(Calendar.MONTH);
int Day = c.get(Calendar.DAY_OF_MONTH);
}catch (Exception e) {
}
}
});
}
class CountDownRunner implements Runnable{
// @Override
public void run() {
while(!Thread.currentThread().isInterrupted()){
try {
doWork();
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}catch(Exception e){
}
}
Button btn = (Button) findViewById(R.id.btn_OK);
btn.setonClickListener(new View.OnClickListener()
{
public void onClick(View view) {
Intent data = new Intent();
setResult(RESULT_OK,data);
Intent i = new Intent(getApplicationContext(),Customer.class);
startActivity(i);
//---closes the activity---
finish();
}
});
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。