-1
我想讓Date對話框選擇器自動填充我的EditText。 有2個EditText,我不知道在我的監聽器中如何編輯文本lanch dialod。片段中的日期選擇器對話框
public class DatePickerFragment extends DialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
Calendar c = Calendar.getInstance();
int year= c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day_of_month = c.get(Calendar.DAY_OF_MONTH);
Log.i(Acceuil.APP_TAG, "DialogFrag method Id: " +this.getId());
DatePickerDialog datePicker = new DatePickerDialog(getActivity(), STYLE_NORMAL, (OnDateSetListener)getActivity(), year,month,day_of_month);
return datePicker;
}
而且在我的活動:
public class AddCar extends FragmentActivity implements OnItemSelectedListener,OnDateSetListener{
EditText registration_ET=null;
EditText control_ET=null;
DialogFragment newFrag= null;
DialogFragment newFrag2= null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addcar_layout);
registration_ET = (EditText) this.findViewById(R.id.firstRegistration_editText);
registration_ET.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i(Acceuil.APP_TAG,"Registration ET clicked!");
newFrag = new DatePickerFragment();
newFrag.show(getSupportFragmentManager(), "DateRegisterId");
}
});
control_ET = (EditText) this.findViewById(R.id.control_editText);
control_ET.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i(Acceuil.APP_TAG,"Registration ET clicked!");
newFrag2 = new DatePickerFragment();
newFrag2.show(getSupportFragmentManager(), "controlId");
}
});
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
Log.i(Acceuil.APP_TAG, "onDateSet AddCar method");
//switch (view.getId())
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
c.set(year, monthOfYear, dayOfMonth);
String date = sdf.format(c.getTime());
}
我要的是更新正確EDITTEXT registration_ET或control_ET depent whitch片段設定日期。 謝謝。
DatePickerDialog中沒有方法setTag .. – dav
setTag不在DatePickerDialog中,它在[DatePicker](http://developer.android.com/reference/android/widget/DatePicker.html)中可用,這就是爲什麼我添加'dialog.getDatePicker()。setTag(getTag());'。 – Gunaseelan
我沒有看到它。感謝您的幫助我從2天開始就這麼做! – dav