Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Android Apk
- Android Apk 이름 변경
- 안드로이드
- apache gzip
- css
- Eclipse
- Exception
- Android
- Android Apk 이름
- R프로그래밍
- tomcat
- DataTable
- error
- release unsigned
- MySQL
- html
- Program type already present
- CSS사용법
- Java
- jQuery
- FLUTTER
- Kotlin
- JavaScript
- android fragment
- release Apk
- Firebase
- android error
- fragment
- java error
- spring
Archives
- Today
- Total
selfstarter
Simple Current Time Example 본문
Simple Current Time Example
It is simple better than using thread
package com.tmoney.taxi.sendmessagedelayed;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
private static final int MESSAGE_TIMER_START = 1000;
Handler timerHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
long now = System.currentTimeMillis();
Date date = new Date(now);
SimpleDateFormat simpleDate = new SimpleDateFormat("hh:mm aa");
String currentTime = simpleDate.format(date);
clockText.setText(currentTime);
Log.d("TEST_LOG", "currentTime:"+currentTime);
sendEmptyMessageDelayed(0, MESSAGE_TIMER_START);
}
};
private TextView clockText;
private Button startBtn;
private Button endBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
clockText = findViewById(R.id.text);
startBtn = findViewById(R.id.start);
endBtn = findViewById(R.id.end);
}
public void startClick(View v) {
timerHandler.sendEmptyMessage(0);
}
public void endClick(View v) {
timerHandler.removeMessages(0);
}
}
'App > Android' 카테고리의 다른 글
Internal error in Firestore (0.6.6-dev) (0) | 2020.04.01 |
---|---|
Animation simple example in Android (0) | 2020.03.30 |
BroadcastReciver app to app in Android (0) | 2020.03.18 |
Using Android getIdentifier (0) | 2020.03.12 |
androidx 사용하지 않기 (0) | 2020.03.12 |
Comments