有什么方法可以重新格式化 datePicker,这样您就可以得到“dd/mm/yyyy”甚至“dd/mm/yy”而不是“mm/dd/yyyy”
这是我当前的代码。
import android.app.Activity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.app.DatePickerDialog.OnDateSetListener;
import java.util.Calendar;
/**
* Created by MOS182 on 7/21/13.
*/
public class AddReminder extends Activity {
TextView Title, Amount, PaymentDate, ReminderDate, ReminderTime;
EditText eTitle, eAmount, ePaymentDate, eReminderDate, eReminderTime;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.reminders_dialog);
initializeVariables();
ePaymentDate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//To show current date in the datepicker
Calendar mcurrentDate = Calendar.getInstance();
int mYear = mcurrentDate.get(Calendar.YEAR);
int mMonth = mcurrentDate.get(Calendar.MONTH);
int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker;
mDatePicker = new DatePickerDialog(AddReminder.this, new OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
/* Your code to get date and time */
selectedmonth = selectedmonth + 1;
ePaymentDate.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Select date");
mDatePicker.show();
}
});
}
private void initializeVariables()
{
Title = (TextView) findViewById(R.id.tvTitle);
Amount = (TextView) findViewById(R.id.tvAmount);
PaymentDate = (TextView) findViewById(R.id.tvPaymentDate);
ReminderDate = (TextView) findViewById(R.id.tvReminderDate);
ReminderTime = (TextView) findViewById(R.id.tvReminderTime);
eTitle = (EditText) findViewById(R.id.etTitle);
eAmount = (EditText) findViewById(R.id.etAmount);
ePaymentDate = (EditText) findViewById(R.id.etPaymentDate);
eReminderDate = (EditText) findViewById(R.id.etReminderDate);
eReminderTime = (EditText) findViewById(R.id.etReminderTime);
}
}
这是我运行代码并选择 ePaymentDate 字段时当前显示的内容。