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 |
Tags
- Android Apk 이름 변경
- FLUTTER
- apache gzip
- release Apk
- Android Apk 이름
- tomcat
- JavaScript
- Firebase
- Android
- 안드로이드
- release unsigned
- DataTable
- java error
- css
- fragment
- MySQL
- spring
- Program type already present
- jQuery
- Eclipse
- html
- android error
- Exception
- Kotlin
- error
- Java
- CSS사용법
- Android Apk
- android fragment
- R프로그래밍
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