片段已添加:TimePick

时间:2015-11-27 08:14:53

标签: android android-fragments datetimepicker android-timepicker

我的应用中有两个timepicker,一个用于 timeIn ,另一个用于 timeOut 。当editText被阻止时,它会显示{ {1}}对话框。

timePicker

现在的问题是 private TimePick tp; tp = new TimePick(); private static EditText timeIn; private static EditText timeOut; timeIn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //shows timePick tp.setFlag(TimePick.FLAG_START_DATE); FragmentTransaction ft = getFragmentManager().beginTransaction(); tp.show(ft, "TimePicker"); } }); timeOut.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tp.setFlag(TimePick.FLAG_END_DATE); FragmentTransaction ft = getFragmentManager().beginTransaction(); tp.show(ft, "TimePicker"); } }); public static class TimePick extends android.app.DialogFragment implements TimePickerDialog.OnTimeSetListener { public static final int FLAG_START_DATE = 00; public static final int FLAG_END_DATE = 01; private int flag = 00; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity())); } public void setFlag(int i) { flag = i; } @Override public void onTimeSet(TimePicker view, int hourofDay, int minute) { if (flag == FLAG_START_DATE) { timeIn.setText(Integer.toString(hourofDay) + ":" + Integer.toString(minute)); TimeIn = timeIn.getText().toString(); } if (flag == FLAG_END_DATE) { timeOut.setText(Integer.toString(hourofDay) + ":" + Integer.toString(minute)); TimeOut = timeOut.getText().toString(); } } } 对话框仅在我双击editText时显示。是否可以将其更改为单击而不是双击?

如果我点击了两次以上,应用程序崩溃并显示timePicker错误。我从之前的post获得了一个解决方案,即添加Fragment already added: TimePick{f1f4f2b #0 TimePicker条件以检查对话框是否显示。但TimePicker怎么样?它有if-else函数吗?

谢谢。

LogCat错误

TimePicker d=tp.getTimepicker();

1 个答案:

答案 0 :(得分:0)

  

是否可以将其更改为单击而不是双击?

是的,为xml中的EditText设置focusableInTouchMode属性为true

   <EditText
    android:focusableInTouchMode="false"
    ...
   />