2 つの ImageButtons があります。1 つは開始日の設定を担当し、もう 1 つは終了日の設定を担当します。それぞれが押されると、DatePickerDialog が表示されます。onCreateDialog メソッドは別のクラス内にあります。そのクラスは次のとおりです。
DatePickerFragment.Java
package com.ThatOneNoob.smarthaul;
import java.util.Calendar;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.widget.DatePicker;
public 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);
}
@Override
public void onDateSet(DatePicker v, int year, int month, int day) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.datesel1:
toDate.setText(new StringBuffer());
}
}
}
明らかに不完全ですが、toDate は、管理することになっている TextView の 1 つです。datesel1 は ImageButton です。TextView を追加して、設定された日付を 01/02/2013 形式で含めます。TextView を static として宣言できないため、このクラス内で呼び出すことはできません。では、onDateSet に TextView を必要な内容に設定する静的メソッドを呼び出させる必要がありますか? または、どうすればよいですか?