レイアウトに2つのテキストビューと2つのボタンがあります。データピッカーをポップアップし、最終的に特定のテキストビューになるように設定するボタンをクリックします。日付データピッカーを使用中に変更されない
例:
Button1のは
をtextview2に設定Textview1 ボタン2のchhose日に設定された日付を選択するが、問題が正しく動作して初めてですが、私は2回目をしようとした場合Textview2に設定ボタン1が、値を変更してみてください。
初回のみ動作良好です.Plzガイド私はよりリークなステップバイステップ基本的な質問申し訳ありません。
// display current date
public void setCurrentDateOnView() {
tvDisplayDate = (TextView) findViewById(R.id.tvDate);
tvDisplayDate2 = (TextView) findViewById(R.id.tvDate2);
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
// set current date into textview
tvDisplayDate.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(month + 1).append("-").append(day).append("-")
.append(year).append(" "));
tvDisplayDate2.setText(tvDisplayDate.getText().toString());
}
public void addListenerOnButton() {
btnChangeDate = (Button) findViewById(R.id.btnChangeDate);
btnChangeDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
btnChangeDate2 = (Button) findViewById(R.id.btnChangeDate2);
btnChangeDate2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DATE_DIALOG_ID2);
}
});
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
System.out.println("onCreateDialog : " + id);
cur = DATE_DIALOG_ID;
// set date picker as current date
return new DatePickerDialog(this, datePickerListener, year, month,
day);
case DATE_DIALOG_ID2:
cur = DATE_DIALOG_ID2;
System.out.println("onCreateDialog2 : " + id);
// set date picker as current date
return new DatePickerDialog(this, datePickerListener, year, month,
day);
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
if (cur == DATE_DIALOG_ID) {
// set selected date into textview
tvDisplayDate.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(" "));
System.out.println("A");
System.out.println(cur);
}
if (cur == DATE_DIALOG_ID2){
tvDisplayDate2.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(" "));
System.out.println("B");
System.out.println(cur);
}
}
};
にShowDialog();非推奨のメッセージ
onCreateDialog非推奨メッセージ
にShowDialog()のパラメータは、クリック
でのTextView日付を設定する2各DatePickerDialogためdatePickerListenerとdatePickerListenerライトコードの内部を作成します。 –
あなたは私があなたを得ることができない説明PLZすることができます –