Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Programming 고급위젯

Similar presentations


Presentation on theme: "Android Programming 고급위젯"— Presentation transcript:

1 Android Programming 고급위젯
이 자료는 모바일IT공학전공 내부 수업자료로 활용하기위해 작성되었으므로 배포 및 인터넷게시를 금한다.

2 날짜/시간 관련 위젯 [activity_main.xml ]
프로젝트명: AndExam6_1_2_3 패키지명: com.example.andexam6_1_2_3 [activity_main.xml ] <LinearLayout xmlns:android=" xmlns:app=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--This class was deprecated in API level > <AnalogClock android:layout_width="match_parent" android:layout_height="wrap_content" /> <DigitalClock android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" /> <Chronometer android:layout_width="match_parent" android:layout_height="wrap_content" android:format="시간 측정: %s" android:gravity="center" android:textSize="30sp" /> <TimePicker android:timePickerMode="spinner" android:layout_width="match_parent" android:layout_height="wrap_content" /> <DatePicker android:datePickerMode="spinner" android:layout_width="match_parent" android:layout_height="wrap_content" /> <CalendarView android:layout_width="match_parent" android:layout_height="match_parent" android:showWeekNumber="false" /> </LinearLayout>

3 날짜/시간 예약 앱 만들기 프로젝트명: Project6_1 패키지명: com.example.project6_1 어플리케이션 설명 타이머기능: <예약시작>과 <예약완료>버튼을 클릭하면 크로노미터가 타이머로 동작한다. 날짜/시간설정: <날짜설정>과<시간설정>을 클릭하면 예약할 날짜와 시간을 변경할 수 있다. <예약완료>를 클릭하면 설정한 날짜와 시간이 결정된다.

4 날짜/시간 예약 앱 만들기 [activity_main.xml ] [activity_main.xml(계속) ]
프로젝트명: Project6_1 패키지명: com.example.project6_1 [activity_main.xml ] <LinearLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" 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:background="#cccccc" android:format="예약에 걸린 시간 %s" android:gravity="center" android:textSize="20dp" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="예약 시작"/> </LinearLayout> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="날짜 설정" /> [activity_main.xml(계속) ] <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="시간 설정" /> </RadioGroup> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <CalendarView android:showWeekNumber="false" android:layout_width="match_parent" android:layout_height="match_parent" /> <TimePicker android:timePickerMode="spinner" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" /> </FrameLayout> </LinearLayout>

5 날짜/시간 예약 앱 만들기 [MainActivity.java(계속) ] [MainActivity.java ]
프로젝트명: Project6_1 패키지명: com.example.project6_1 [MainActivity.java ] public class MainActivity extends AppCompatActivity { Button btnStart, btnEnd; Chronometer chrono; RadioButton radioCal, radioTime; CalendarView calView; TimePicker tPicker; TextView tvYear, tvMonth, tvDay, tvHour, tvMinute; @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); // 라디오버튼2개 radioCal = (RadioButton) findViewById(R.id.radioCal); radioTime = (RadioButton) findViewById(R.id.radioTime); // FrameLayout의 2개위젯 calView = (CalendarView) findViewById(R.id.calendarView1); tPicker = (TimePicker) findViewById(R.id.timePicker1); // 텍스트뷰중에서 연,월,일,시,분 숫자 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); [MainActivity.java(계속) ] radioCal.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { tPicker.setVisibility(View.INVISIBLE); calView.setVisibility(View.VISIBLE); } }); radioTime.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) { //예약시작버튼을 누를때마다 크로노미터를 0으로 초기화 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); java.util.Calendar curDate = java.util.Calendar.getInstance(); curDate.setTimeInMillis((calView.getDate())); tvYear.setText(Integer.toString(curDate.get(Calendar.YEAR))); tvMonth.setText(Integer.toString(1+curDate.get(Calendar.MONTH)));//월은 0부터 tvDay.setText(Integer.toString(curDate.get(Calendar.DATE))); //일 // 타임피커에서 설정한 시간/분을 구해서 해당하는 텍스트뷰에 채운다 tvHour.setText(Integer.toString(tPicker.getCurrentHour())); tvMinute.setText(Integer.toString(tPicker.getCurrentMinute())); } }); } }

6 날짜/시간 예약 앱 만들기 [MainActivity.java(계속) ]
프로젝트명: Project6_1 패키지명: com.example.project6_1 [MainActivity.java(계속) ] btnEnd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { chrono.stop(); // 타이머가 중지하면 글자가 파란색으로 chrono.setTextColor(Color.BLUE); java.util.Calendar curDate = java.util.Calendar.getInstance(); curDate.setTimeInMillis((calView.getDate())); tvYear.setText(Integer.toString(curDate.get(Calendar.YEAR))); tvMonth.setText(Integer.toString(1+curDate.get(Calendar.MONTH))); //월은 0부터 tvDay.setText(Integer.toString(curDate.get(Calendar.DATE))); //일 // 타임피커에서 설정한 시간/분을 구해서 해당하는 텍스트뷰에 채운다 tvHour.setText(Integer.toString(tPicker.getCurrentHour())); tvMinute.setText(Integer.toString(tPicker.getCurrentMinute())); } }); } // onCreate() } // MainActivity

7 날짜/시간 예약 앱 만들기 [activity_main.xml ] [activity_main.xml(계속) ]
프로젝트명: Project6_1 패키지명: com.example.project6_1 [activity_main.xml(계속) ] <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#cccccc" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="예약완료" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" 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: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:text="00"/> [activity_main.xml ] <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: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:text="00"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="분 예약됨"/> </LinearLayout> </LinearLayout>

8 프로그래스바,시크바,래이팅바 [activity_main.xml ]
프로젝트명: AndExam6_12 패키지명: com.example.andexam6_12 [activity_main.xml ] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <ProgressBar style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:max="100" android:progress="20" android:secondaryProgress="50" /> <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:progress="20" /> <RatingBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="20dp" android:numStars="5" android:rating="1.5" android:stepSize="0.5" /> </LinearLayout>

9


Download ppt "Android Programming 고급위젯"

Similar presentations


Ads by Google