在我的应用程序中,我必须从用户那里获取日期。
首先,我使用一个按钮,当用户单击该按钮时,将出现一个对话框,其中包含日期选择器并在一个 TextView 中获取结果。
现在我想用 EditView 替换按钮。单击 EditView 时,必须出现对话框,并且不应出现任何键盘。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.report);
EmployeeGlobal eg=(EmployeeGlobal)getApplicationContext();
String uid=eg.getMainUserId();
ArrayList<String>list=eg.getAllProjects(uid);
Spinner spinner = (Spinner)findViewById(R.id.all_projs);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);
Toast.makeText(getApplicationContext(), "Report"+uid, Toast.LENGTH_LONG).show();
mStartDateDisplay=(TextView)findViewById(R.id.strdate);
mEndDateDisplay = (TextView) findViewById(R.id.enddate);
mEndDate = (Button) findViewById(R.id.end_dateb);
mStartDate=(Button)findViewById(R.id.start_dateb);
mYear=c1.get(Calendar.YEAR);
mMonth = c1.get(Calendar.MONTH);
mDay = c1.get(Calendar.DAY_OF_MONTH);
mStartDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_START);
//updateDisplay(mStartDateDisplay);
}
});
mEndDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_END);
//updateDisplay(mEndDateDisplay);
}
});
}
private void updateDisplay(TextView T) {
T.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append("-")
.append(mDay).append("-")
.append(mYear).append(" "));
}
private DatePickerDialog.OnDateSetListener mFromDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay(mStartDateDisplay);
}
};
private DatePickerDialog.OnDateSetListener mToDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay(mEndDateDisplay);
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_END:
return new DatePickerDialog(this,mToDateSetListener, mYear, mMonth, mDay);
case DATE_DIALOG_START:
return new DatePickerDialog(this,mFromDateSetListener,mYear, mMonth, mDay);
}
return null;
}
所以请有人帮助我吗?