gpt4 book ai didi

android - 再次选择日期时,如何在 EditText 中显示最后选择的日期?

转载 作者:行者123 更新时间:2023-11-29 17:52:42 25 4
gpt4 key购买 nike

enter image description here这是选择日期的来源。它工作正常,但我想在再次选择日期时更改日期。

private int year;
private int month;
private int day;
signup_bday=(EditText)findViewById(R.id.edittext_signup_birthday);
signup_bday.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Calendar mcurrentDate=Calendar.getInstance();
year=mcurrentDate.get(Calendar.YEAR);
month=mcurrentDate.get(Calendar.MONTH);
day=mcurrentDate.get(Calendar.DAY_OF_MONTH);

DatePickerDialog mDatePicker=new DatePickerDialog(CreateAccountActivity.this, new OnDateSetListener()
{
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday)
{
signup_bday.setText(new StringBuilder().append(month + 1).append("-").append(day).append("-").append(year).append(" "));
}
},year, month, day);
mDatePicker.setTitle("Please select date");
mDatePicker.show();
}
});

enter image description here

最佳答案

好的,我解决了你的问题,这是代码,

public class MainActivity extends Activity 
{
private int year;
private int month;
private int day;
private EditText signup_bday;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
signup_bday=(EditText)findViewById(R.id.edittext_signup_birthday);
signup_bday.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Calendar mcurrentDate=Calendar.getInstance();
year=mcurrentDate.get(Calendar.YEAR);
month=mcurrentDate.get(Calendar.MONTH);
day=mcurrentDate.get(Calendar.DAY_OF_MONTH);

DatePickerDialog mDatePicker = new DatePickerDialog(MainActivity.this, new OnDateSetListener()
{
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday)
{
year = selectedyear;
month = selectedmonth;
day = selectedday;
signup_bday.setText(new StringBuilder().append(month + 1).append("-").append(day).append("-").append(year).append(" "));
}
},year, month, day);
mDatePicker.setTitle("Please select date");
mDatePicker.show();
}
});
}
}

您只需要在 onDateSet() 方法中添加以下几行,

year = selectedyear; 
month = selectedmonth;
day = selectedday;

关于android - 再次选择日期时,如何在 EditText 中显示最后选择的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21872949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com