我需要一些关于时间选择器对话框的帮助。这是代码
static final int dialog_id = 0;
int hour,minute;
Button date;
Button time;
DatePicker dp;
TimePicker tp;
EditText et;
EditText et1;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
date = (Button) findViewById(R.id.button1);
time = (Button) findViewById(R.id.button2);
et = (EditText) findViewById(R.id.editText1);
et1 = (EditText) findViewById(R.id.EditText01);
showDialog(dialog_id);
}
protected Dialog onCreateDialogDialog(int id)
{
switch(id)
{
case dialog_id:
return new TimePickerDialog(this, mTimeSetListener, hour, minute, false);
}
return null;
}
et.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
date();
}
});
et1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TimePickerDialog.OnTimeSetListener mTimeSetListener=
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
et1.setText( hour + ":" + minute);
}
};
}
});
为mTimeSetListener的timepicker创建对话框时返回new时出错。 这来自一个教程,但它给我发了一个错误..
答案 0 :(得分:0)
您的mTimeSetListener
应该在onClickListener
之外,否则TimePickerDialog
无法看到<{1}}
答案 1 :(得分:0)
将mTimeSetListener放在onClickListener之外,因为可以看到TimePickerDialog,并记得下次完整发布错误详情...