少年恃险若平地,独倚长剑凌清秋。这篇文章主要讲述Android初学第76天相关的知识,希望能为你提供帮助。
android初学第76天【Android初学第76天】16_CameraIntent
代码
Criminalintent
DatePickerFragment.java
package com.bignerdranch.android.criminalintent;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class DatePickerFragment extends DialogFragment {public static final String EXTRA_DATE =
"com.bignerdranch.android.criminalintent.date";
private static final String ARG_DATE = "date";
private DatePicker mDatePicker;
public static DatePickerFragment newInstance(Date date) {
Bundle args = new Bundle();
args.putSerializable(ARG_DATE, date);
DatePickerFragment fragment = new DatePickerFragment();
fragment.setArguments(args);
return fragment;
}@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Date date = (Date) getArguments().getSerializable(ARG_DATE);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
View v = LayoutInflater.from(getActivity())
.inflate(R.layout.dialog_date, null);
mDatePicker = (DatePicker) v.findViewById(R.id.dialog_date_picker);
mDatePicker.init(year, month, day, null);
return new AlertDialog.Builder(getActivity())
.setView(v)
.setTitle(R.string.date_picker_title)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int year = mDatePicker.getYear();
int month = mDatePicker.getMonth();
int day = mDatePicker.getDayOfMonth();
Date date = new GregorianCalendar(year, month, day).getTime();
sendResult(Activity.RESULT_OK, date);
}
})
.create();
}private void sendResult(int resultCode, Date date) {
if (getTargetFragment() == null) {
return;
}Intent intent = new Intent();
intent.putExtra(EXTRA_DATE, date);
getTargetFragment()
.onActivityResult(getTargetRequestCode(), resultCode, intent);
}
}
推荐阅读
- Android初学第85天
- Android初学第78天
- usb怎样安装系统,本文教您电脑怎样安装系统
- u盘格式化单位分配,本文教您u盘格式化分配单元大小
- 如何制作u盘系统安装盘,本文教您如何制作u盘打开盘
- usb打开,本文教您华硕笔记本怎样设置u盘打开
- usb接口,本文教您电脑usb接口没反应
- 制作u盘系统安装盘,本文教您如何制作u盘打开安装盘
- usb端口,本文教您如何禁用USB接口