我想在同一活动中实施两个时间选择器。一个用于开始时间,另一个用于结束时间。 现在的问题是,我想在4个不同的变量中存储4个时间选择器的值(小时,分钟),以将它们插入到sqlite数据库中。我已经在谷歌搜索了很多,但没有找到有用的文章。 任何类型的帮助都非常感谢。 谢谢......
这是代码
public class Time扩展AppCompatActivity {
static final int START_TIME_ID=0;
static final int END_TIME_ID=1;
EditText edit_start_time,edit_end_time;
public int hour,minute;
private int chour,cminute;
public Time(){
final Calendar calendar=Calendar.getInstance();
chour=calendar.get(Calendar.HOUR_OF_DAY);
cminute=calendar.get(Calendar.MINUTE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_Time);
edit_start_time = (EditText) findViewById(R.id.edit_start_time);
edit_end_time = (EditText) findViewById(R.id.edit_end_time);
edit_start_time.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(START_TIME_ID);
}
});
edit_end_time.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
showDialog(END_TIME_ID);
}
});
}
private TimePickerDialog.OnTimeSetListener mStartTime=new TimePickerDialog.OnTimeSetListener()
{
public void onTimeSet(TimePicker view,int hourofday,int min)
{
hour=hourofday;
minute=min;
}
};
private TimePickerDialog.OnTimeSetListener mEndTime=new TimePickerDialog.OnTimeSetListener()
{
public void onTimeSet(TimePicker view,int hourofday,int min)
{
hour=hourofday;
minute=min;
}
};
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case START_TIME_ID:
return new TimePickerDialog(this,mStartTime,chour,cminute,false);
case END_TIME_ID:
return new TimePickerDialog(this,mEndTime,chour,cminute,false);
}
return null;
}