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 |
| 31 |
Tags
- OGNL
- 생성자
- 메서드
- paint
- JSP
- 어노테이션
- oracle
- JavaScript
- Spring
- HTML
- 국제화
- mybatis
- 클래스
- struts2
- 기본
- 이클립스
- 예외처리
- 메소드
- 전화걸기
- AWT
- Graphic
- 배열
- 오버로딩
- Eclips
- Menu
- 안드로이드
- Android
- layout
- Java
- 에러페이지
Archives
- Today
- Total
note
Android 간단한 이벤트2 본문
package com.commonsware.android.skeleton2;
import java.util.Date;
import java.text.SimpleDateFormat;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Date;
public class NowRedux extends Activity implements View.OnClickListener{
//이벤트 리스너
Button btn;
SimpleDateFormat sf = new SimpleDateFormat("yyyy년 mm월 dd일 a HH:mm:ss");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//main.xml 등록
setContentView(R.layout.main);
//button 객체 호출(이벤트 소스)
btn=(Button)findViewById(R.id.button);
//이벤트 소스와 이벤트 리스너가 구현된 객체를 연결
btn.setOnClickListener(this);
updateTime();
}
//이벤트 핸들러
public void onClick(View view){
updateTime();
}
private void updateTime(){
btn.setText(sf.format(new Date()));
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- fill_parent = 부모영역까지 채운다 wrap_parent =감싼다 -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
'Android > 기본' 카테고리의 다른 글
| Android 필드 박스 (0) | 2012.01.05 |
|---|---|
| Android 이미지 넣기 (0) | 2012.01.05 |
| Android 간단한 이벤트 3 (0) | 2012.01.05 |
| Android 간단한 이벤트 (0) | 2012.01.05 |
| android 기본 (0) | 2012.01.05 |