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
- 알고리즘
- 리액트댓글기능
- 자바스크립트
- js코테
- 백준알고리즘
- 프로그래머스
- JS프로그래머스
- HTML5
- 백준구현
- 다이나믹프로그래밍
- 코테
- css기초
- 백준골드
- 리액트
- HTML
- 몽고DB
- 안드로이드 스튜디오
- 프로그래머스코테
- 포이마웹
- JS
- 백준js
- 백준구현문제
- CSS
- dp알고리즘
- 백준nodejs
- 프로그래머스JS
- 리액트커뮤니티
- 코딩테스트
- 백준
- 익스프레스
Archives
- Today
- Total
개발새발 로그
안드로이드 스튜디오 고급위젯 간단하게 다루기 - 날짜/시간 예약 앱 만들기 본문
오늘은 저번에 배운 고급 위젯들을 가지고 간단한 앱을 만들어 보겠습니다.
날짜/시간 예약앱
- 예약 시작을 누르면 타이머가 실행되며 예약 완료를 누르면 해당 타이머가 멈춘다
- 날짜 설정 라디오 버튼을 누르면 캘린더가 나와 날짜를 클릭 가능하고, 시간 설정 라디오 버튼을 클릭하면 시간 설정이 가능하다.
- 예약 완료를 누르게 되면 타이머가 종료되며 걸린 시간이 표시되고 하단에 예약한 날짜와 시간이 출력된다.
화면 디자인 코드
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Chronometer
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/chronometer1"
android:format="예약에 걸린 시간 %s"
android:gravity="center"
android:textSize="20dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnStart"
android:text="예약 시작"
/>
</LinearLayout>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rdoCal"
android:text="날짜 설정"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rdoTime"
android:text="시간 설정"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CalendarView
android:id="@+id/calenderView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:showWeekNumber="false"/>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:timePickerMode="spinner"/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnEnd"
android:text="예약 완료"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvYear"
android:text="0000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="년"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvMonth"
android:text="00"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="월"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvDay"
android:text="00"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="일"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvHour"
android:text="00"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="시"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvMinute"
android:text="00"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="분"/>
</LinearLayout>
</LinearLayout>
자바 코드
package org.techtown.tistory_widget;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.Chronometer;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity {
Chronometer chrono;
Button btnStart,btnEnd;
RadioButton rdoCal,rdoTime;
CalendarView calView;
TimePicker tPicker;
TextView tvYear,tvMonth,tvDay,tvHour,tvMinute;
int selectYear,selectMonth,selectDay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("시간 예약");
btnStart = (Button) findViewById(R.id.btnStart);
btnEnd = (Button)findViewById(R.id.btnEnd);
chrono = (Chronometer)findViewById(R.id.chronometer1);
rdoCal = (RadioButton)findViewById(R.id.rdoCal);
rdoTime = (RadioButton) findViewById(R.id.rdoTime);
tPicker = (TimePicker) findViewById(R.id.timePicker1);
calView = (CalendarView)findViewById(R.id.calenderView1);
tvYear=(TextView) findViewById(R.id.tvYear);
tvMonth=(TextView) findViewById(R.id.tvMonth);
tvDay=(TextView) findViewById(R.id.tvDay);
tvHour=(TextView) findViewById(R.id.tvHour);
tvMinute=(TextView) findViewById(R.id.tvMinute);
tPicker.setVisibility(View.INVISIBLE);
calView.setVisibility(View.INVISIBLE);
rdoCal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tPicker.setVisibility(View.INVISIBLE);
calView.setVisibility(View.VISIBLE);
}
});
rdoTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tPicker.setVisibility(View.VISIBLE);
calView.setVisibility(View.INVISIBLE);
}
});
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
chrono.setTextColor(Color.RED);
}
});
btnEnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
chrono.stop();
chrono.setTextColor(Color.BLUE);
tvYear.setText(Integer.toString(selectYear));
tvMonth.setText(Integer.toString(selectMonth));
tvDay.setText(Integer.toString(selectDay));
tvHour.setText(Integer.toString(tPicker.getHour()));
tvMinute.setText(Integer.toString(tPicker.getMinute()));
}
});
calView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int dayOfMonth) {
selectYear=year;
selectMonth=month+1;
selectDay=dayOfMonth;
}
});
}
}
기능 설명
실행 화면
728x90
반응형
LIST
'안드로이드' 카테고리의 다른 글
안드로이드 스튜디오- 뷰 컨테이너 (0) | 2022.05.22 |
---|---|
안드로이드 스튜디오-오류 (0) | 2022.05.20 |
안드로이드 스튜디오 고급위젯 간단하게 다루기 (0) | 2022.05.20 |
안드로이드 스튜디오-그리드 레이아웃으로 간이 계산기 만들기 (0) | 2022.05.17 |
안드로이드 스튜디오 레이아웃 익히기-프레임 레이아웃 (0) | 2022.05.17 |