일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 포켓몬 GO
- 보라카이
- loop
- 신도림
- 샘플
- Check
- 포켓볼
- swift
- error
- afterdelay
- 아이폰7
- push
- 스마트폰
- 신도림 테크노마트
- LG유플러스
- Example
- UITableView
- 앱스토어
- IOS
- UIView
- simulator
- swift3
- 페이백
- Xcode
- setting
- 얻는법
- 공략
- GCD
- 해몽
- Bitcode
- Today
- Total
도래울
안드로이드 달력 만들기 본문
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:background="#FFFFFFFF"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="PRE"
android:id="@+id/pre"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="today"
android:id="@+id/today"
android:layout_weight="3"
android:textColor="#FF000000"
android:gravity="center_horizontal|center_vertical"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="NEXT"
android:id="@+id/next"
android:layout_weight="1"
/>
</LinearLayout>
<TableLayout
android:id="@+id/week"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="true"
android:stretchColumns="true"
android:background="#FF8DC701"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="일"
android:textColor="#FFFF0000"
android:gravity="center_horizontal" />
<TextView
android:text="월"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:textColor="#FF000000"
android:layout_height="wrap_content"/>
<TextView
android:text="화"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:textColor="#FF000000"
android:layout_height="wrap_content"/>
<TextView
android:text="수"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:textColor="#FF000000"
android:layout_height="wrap_content"/>
<TextView
android:text="목"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:textColor="#FF000000"
android:layout_height="wrap_content"/>
<TextView
android:text="금"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:textColor="#FF000000"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="토"
android:textColor="#FF0000FF"
android:gravity="center_horizontal"/>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/table"
android:background="#FFF6F3A4"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
/>
</LinearLayout>
HomeworkCalendar2 .java
package exam.HomeworkCalendar2;
import java.util.Date;
import java.util.Vector;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
public class HomeworkCalendar2 extends Activity {
/** Called when the activity is first created. */
Vector vec;
int firstDay;
int totDays;
int iYear;
int iMonth;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Date today = new Date();
iYear = today.getYear();
iMonth = today.getMonth();
vec = new Vector();
TableLayout table = (TableLayout)findViewById( R.id.table );
for( int i = 0 ; i < 6 ; i++ ){
TableRow tr = new TableRow( this );
for( int j = 0 ; j < 7 ; j++ ){
TextView tv = new TextView( this );
if( j == 0 )
tv.setTextColor( Color.RED );
else if( j == 6 )
tv.setTextColor( Color.BLUE );
else
tv.setTextColor( Color.BLACK );
tv.setGravity( Gravity.CENTER_HORIZONTAL );
tr.addView( tv );
vec.add( tv );
}
table.addView( tr );
}
table.setStretchAllColumns( true );
table = (TableLayout)findViewById( R.id.week );
table.setStretchAllColumns( true );
setCalendar( iYear, iMonth );
Button btn = (Button)findViewById( R.id.pre );
btn.setOnClickListener( new Button.OnClickListener(){
public void onClick(View v) {
iMonth--;
setCalendar( iYear, iMonth );
}
});
btn = (Button)findViewById( R.id.next );
btn.setOnClickListener( new Button.OnClickListener(){
public void onClick(View v) {
iMonth++;
setCalendar( iYear, iMonth );
}
});
}
private void setCalendar( int year, int month ){
Date date = new Date();
date.setYear( year );
date.setMonth( month );
date.setDate( 1 );
firstDay = date.getDay();
totDays = 31;
for( int i = 29 ; i <= 32 ; i++ ){
date.setDate( i );
if( date.getDate() == 1 ){
totDays = i - 1;
break;
}
}
Log.i("mylog", firstDay + " " + totDays );
date = new Date();
date.setYear( year );
date.setMonth( month );
iYear = date.getYear();
iMonth = date.getMonth();
TextView tvToday = (TextView)findViewById( R.id.today );
tvToday.setText( (iYear + 1900) + "년" + (iMonth + 1) + "월");
for( int i = 0 ; i < vec.size() ; i++ ){
((TextView)vec.get( i )).setText("");
}
int iDate = 1;
for( int i = firstDay ; i < firstDay + totDays; i++ ){
((TextView)vec.get( i )).setText( String.valueOf( iDate++ ) );
}
}
}
'개발 > Android' 카테고리의 다른 글
원하는 시간에 작업을 수행하려면? - AlarmManager 사용하기 (0) | 2016.02.05 |
---|---|
안드로이드에서 Device의 고유값 알아보기 (0) | 2016.02.05 |
[Android] AlarmManger - 알람매니저 : Receiver, Notification - 리시버, 알림, 노티피케이션 (1) | 2016.02.05 |
안드로이드 Notification 이 Clear 되지 않도록 하는 방법 (0) | 2016.02.05 |
[Android] Notification (0) | 2016.02.05 |