好吧,我這樣做,有一個活動和延伸DialogFragment並實現DatePickerDialog.OnDateSetListener我想從DatePicker的
的事情是,當用戶點擊一個按鈕dataPicker出現了另一類稱爲MyPicker的應用並且我想從datePicker中獲取該日期,以表明它是活動的texfield。
你如何推薦我這樣做?
好吧,我這樣做,有一個活動和延伸DialogFragment並實現DatePickerDialog.OnDateSetListener我想從DatePicker的
的事情是,當用戶點擊一個按鈕dataPicker出現了另一類稱爲MyPicker的應用並且我想從datePicker中獲取該日期,以表明它是活動的texfield。
你如何推薦我這樣做?
如果要更改日期在日期選擇器然後你可以這樣做
datePicker.setOnDateChangeListner(new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year1,
int monthOfYear1, int dayOfMonth1) {
year = year1;
monthOfYear = monthOfYear1;
dayOfMonth = dayOfMonth1;
}
}
);
你好這個問題已經被問很多時間計算器.. 你可以做一些事情一樣覺得─
public class MainActivity extends Activity {
TextView textDate;
private int year;
private int month;
private int day;
static final int DATE_DIALOG_ID = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textDate = (TextView) findViewById(R.id.text_date);
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
textDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, year, month,
day);
}
return null;
}
// updates the date we display in the TextView
private void updateDisplay() {
/*
* Hide virtual keyboard
*/
textDate.setText(new StringBuilder()
// Month is 0 based so add 1
.append(year).append("-").append(month + 1).append("-")
.append(day).append(""));
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int myear, int monthOfYear,
int dayOfMonth) {
year = myear;
month = monthOfYear;
day = dayOfMonth;
updateDisplay();
}
};
}
的演示環節是here-
是的,有一種不同的方式!!我有另一個類是一個DialogFragment的日期選擇器,我想採取日期actitvy –
然後嘗試使用對象或使用靜態類調用.. 或爲什麼不改變你的類喜歡我的.. –
因爲這是我老師給的一個家庭作業!我必須用它完成它!!說明「然後嘗試使用對象或靜態類調用」請完整代碼和設計請 –
public class MainActivity extends Activity implements OnClickListener {
private Button mDateButton;
private Calendar mCalen;
private int day;
private int month;
private int year;
private static final int DATE_PICKER_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDateButton = (Button) findViewById(R.id.date_button);
mCalen = Calendar.getInstance();
day = mCalen.get(Calendar.DAY_OF_MONTH);
month = mCalen.get(Calendar.MONTH);
year = mCalen.get(Calendar.YEAR);
mDateButton.setOnClickListener(this);
}
@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_PICKER_ID:
return new DatePickerDialog(this, datePickerListener,
year, month, day);
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener =
new DatePickerDialog.OnDateSetListener() {
// while dialog box is closed, below method is called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
// Set the Date String in Button
mDateButton.setText(day + "/" + (month + 1) + "/" + year);
}
};
@Override
public void onClick(View v) {
showDialog(DATE_PICKER_ID);
}
}
,查http:// rajeshvijayakumar.blogspot.in/2013/01/ics-date-picker-example-in-android.html,if usefull then vote up – Dev
試試我的答案.. –