我是一個絕對的初學者,所以我仍然在學習所有的概念。我試圖用碎片創建一個2日期選擇器的活動。 1表示配置單元設置日期,1表示女王的生日日期 - 兩者都在1個活動中,並且都在單獨的EditText框中填充。有沒有人可以幫助我? Br Iceni養蜂人。Android Date Picker Fragment - 2在同一活動中
0
A
回答
0
嘗試更新的答案對我來說
public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener {
public static final String LOGTAG = "APIARYMANAGER";
private static final String TAG = MainActivity.class.getSimpleName();
private static String DATEPICKER_TAG = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void datePickerHiveSetupDate(View view) {
DatePickerFragmentSetupDate fragment = new DatePickerFragmentSetupDate();
fragment.show(getSupportFragmentManager(), "date1");
}
public void setHiveQueenBirthdayDate(View view) {
DatePickerFragmentQueenBDayDate fragment = new DatePickerFragmentQueenBDayDate();
fragment.show(getSupportFragmentManager(), "date2");
}
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Calendar cal = new GregorianCalendar(year, month, dayOfMonth);
if (DATEPICKER_TAG.trim().equals("SETUP_DATE"))
setHiveSetupDate(cal);
else
setHiveQBDayDate(cal);
}
public void setHiveSetupDate(final Calendar calendar) {
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK);
((TextView) findViewById(R.id.editTextHiveSetupDate)).setText(dateFormat.format(calendar.getTime()));
}
public void setHiveQBDayDate(final Calendar calendar) {
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK);
((TextView) findViewById(R.id.editTextHiveQueenBirthday)).setText(dateFormat.format(calendar.getTime()));
}
public static class DatePickerFragmentSetupDate extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
DATEPICKER_TAG = "SETUP_DATE";
return new DatePickerDialog(getActivity(),
(DatePickerDialog.OnDateSetListener) getActivity(), year, month, day);
}
}
public static class DatePickerFragmentQueenBDayDate extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
DATEPICKER_TAG = "SETUP_QUEEN_DATE";
return new DatePickerDialog(getActivity(),
(DatePickerDialog.OnDateSetListener) getActivity(), year, month, day);
}
}
}
+0
感謝您的快速回復Sachin。我試圖根據你的代碼實現2日期選擇器。我在onDateSet有問題。我似乎只能有一個方法,所以兩個日期選擇器更新一個EditText框。 – IceniBeekeeper
+0
我該如何發佈我的代碼? – IceniBeekeeper
+0
和你想要更新兩個不同的edittext或一個edittext?請解釋一下。 – Sach
相關問題
- 1. Android Date Picker幫助!
- 2. Android Date Picker pre 1900
- 3. Android 4.1.1/4.1.2 Date Picker Galaxy S3
- 4. Date Picker noob
- 5. Kivy Date Picker Widget
- 6. Android - 2活動在同一時間
- 7. Selenium Java Date Picker
- 8. HTML Date Picker
- 9. Joomla Date Picker
- 10. Jquery Date picker tabs
- 11. jquery date picker
- 12. Scala Swing Date Picker
- 13. 2 amigos/yii2-date-picker-widget年份驗證
- 14. Date Picker Selected Cell CSS
- 15. Javascript date picker multiple select
- 16. Bootstrap Date Picker中的限制
- 17. Jquery Date Picker與不同的鏈接
- 18. 2在同一活動中的ListViews
- 19. Android - Fragment 2顯示回主片段與活動
- 20. Tabhost和fragment活動
- 21. Swipe Fragment 3活動
- 22. 如何在Fragment實現中顯示不同的活動?
- 23. 來自Fragment Tab的Android加載活動
- 24. 從主要活動取代android Fragment
- 25. 在jquery date picker中需要幫助
- 26. 在jquery date picker的beforeShowDay中添加html
- 27. Date Picker的多個實例
- 28. Date Time Picker Visual Studio 2012
- 29. 創建一個java Date Picker組件?
- 30. jquery date picker z-index問題
的可能的複製[如何設置2個不同的EditText 2 timepicker?](http://stackoverflow.com/questions/41998592/how-to-set工作-2-timepicker-in-2-different-edittext) –