DatePickerの例とOnDateChangedListener、onDateChangedなどのメソッドの使い方を説明するチュートリアルを教えてください。実際にはいくつかのサイトを調べていますが、明確なアイデアは得られませんでした。DatePickerの例android
ありがとうございました
DatePickerの例とOnDateChangedListener、onDateChangedなどのメソッドの使い方を説明するチュートリアルを教えてください。実際にはいくつかのサイトを調べていますが、明確なアイデアは得られませんでした。DatePickerの例android
ありがとうございました
DatePickerのAndroidリファレンスはかなり良いです。それを見てくださいhere。
private DatePicker datePicker;
//monthofYear is between 0-11
datePicker.init(2010, 11, 1, new OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
// Notify the user.
}
});
を参照してください。 Example();ここをクリック
これはダイアログに関するものですが、MiyaはActivityのDatePickerを必要とします。 –
@Paresh Mayani Miyaは同じものが必要です。 –
Yaa ..私はDatePickerが必要です、私を助けることができますか? – Jomia
このデータピッカーの例を確認してください:Example of DATE PICKER。
Step 1 : create a java file:
package com.example.babs;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.app.FragmentManager;
public class EditUserInfo extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_edit_view);
}
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
// pgrm mark ---- ---- ----- ---- ---- ----- ---- ---- ----- ---- ---- -----
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
public void showDatePickerDialog(View v) {
FragmentManager fragmentManager = getFragmentManager();
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(fragmentManager, "datePicker");
}
}// end main class EditUserInfo
step 2: your xml file must contain :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fillViewport="true" >
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pick_date"
android:onClick="showDatePickerDialog" />
あなたはこのコードを試すことができます。
public
static class DatePickerFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
DateEdit.setText(day + "/" + (month + 1) + "/" + year);
}
}
が
Example of DatePickerFragment and TimePickerFragmentから撮影します。
この例では、DatePickerではなくDatePickerDialogを使用しています。これらのメソッド(OnDateChangedListener、onDateChanged)はDatePickerDialogでのみ使用できますか? – Jomia
onDateChangedListenerは単なるコールバックメソッドです。 public void init(int year、int monthOfYear、int dayOfMonth、DatePicker.OnDateChangedListener onDateChangedListener) – Raunak
@Miyaはそのヘルプを行いますか? – Raunak