时间选择器没有显示,我不知道和出了什么问题。我认为问题是在case语句中,我不知道我应该在case语句中写什么来显示时间选择器,这是我的源代码。请告诉我我在这里缺少什么?
public class MainActivity extends ActionBarActivity implements OnClickListener{
private Button btnStart,btnCalculate,btnTime;
static final int DATE_START_DIALOG_ID = 0;
private int mhourOfDay=0;
private int mminute=0;
boolean is24HourView2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTime=(Button) findViewById(R.id.button2);
btnTime.setOnClickListener(this);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_START_DIALOG_ID:
}
return null;
}
//Time picker
private TimePickerDialog.OnTimeSetListener mTimeSetListener
=new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mhourOfDay=hourOfDay;
mminute=minute;
Toast.makeText(MainActivity.this,"hourOfDay is="+mhourOfDay+"minute="+mminute,Toast.LENGTH_LONG).show();
}
};
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button2:
showDialog(TIME_START_DIALOG_ID);
break;
default:
break;
}
}
}
答案 0 :(得分:0)
您需要在Switch语句中返回TimePickerDialog.OnTimeSetListener
:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_START_DIALOG_ID:
return new TimePickerDialog(this,mTimeSetListener, mHour, mMinute, false);
}
return null;
}