gpt4 book ai didi

android - 时间选择器对话框 : onTimeSet never called on samsung devices with touchwiz

转载 作者:行者123 更新时间:2023-11-30 02:52:57 25 4
gpt4 key购买 nike

我有 2 个 Edittext,触摸时会弹出一个时间选择器对话框:

public class MainActivity extends Activity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initTimePicker();
}

private void initTimePicker()
{
Calendar mcurrentTime = Calendar.getInstance();
final int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
final int minute = mcurrentTime.get(Calendar.MINUTE);

final EditText deplacementD = (EditText) findViewById(R.id.editText1);
final EditText deplacementF = (EditText) findViewById(R.id.editText2);


deplacementD.setInputType(InputType.TYPE_NULL);
deplacementF.setInputType(InputType.TYPE_NULL);

// Attachement du timepicker
deplacementD.setOnTouchListener(getTimePicker(hour, minute, "Start"));
deplacementF.setOnTouchListener(getTimePicker(hour, minute, "End"));

}

private OnTouchListener getTimePicker(final int heure, final int minute, final String titre)
{
return new OnTouchListener() {

private boolean validated = false;

@Override
public boolean onTouch(View v, MotionEvent event) {

final EditText editTouched = (EditText) v;

Log.d("Timepicker", "On Touch event");
if (event.getAction() == MotionEvent.ACTION_UP) {
Log.d("Timepicker", "Motion event UP");

TimePickerDialog mTimePicker;

Log.d("Timepicker", "New timepickerdialog instance");
mTimePicker = new TimePickerDialog(editTouched.getContext(),
new TimePickerDialog.OnTimeSetListener() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute)
{
Log.d("Timepicker", "OnTimeSet called");
if (validated)
editTouched.setText(String
.format("%02d:%02d", hourOfDay, minute));
}

}, 00, 00, true);// Yes 24 hour time

Log.d("Timepicker", "Timepicker title set");
mTimePicker.setTitle(titre);

mTimePicker.setButton(DialogInterface.BUTTON_NEGATIVE, "CANCEL",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which)
{
Log.d("Timepicker", "Cancel Clicked");
validated = false;
}
});

mTimePicker.setButton(DialogInterface.BUTTON_POSITIVE,
getString(android.R.string.ok),
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which)
{
Log.d("Timepicker", "Ok called");
validated = true;
}
});
Log.d("Timepicker", "Timepicker show()");
mTimePicker.show();
Log.d("Timepicker", "out of getTimePicker return true");
return true;
}
Log.d("Timepicker", "out of getTimePicker return false");
return false;
}
};
}
}

在现有的 Android 设备(nexus s、4、5)上,一切都运行良好。当我单击肯定按钮时,出现时间选择器对话框并设置编辑文本。

相反,对于 Samsung 设备(S4 4.4.2 和 Note II 4.3),对话框会出现,但永远不会调用 onTimeSet。不过 logcat 中没有错误。

这是放入 getTimepicker() 的日志消息的结果:

在 nexus 设备上:

05-26 09:45:51.850: D/Timepicker(3219): Attaching timepicker
05-26 09:45:51.850: D/Timepicker(3219): Inside getTimePicker()
05-26 09:45:58.007: D/Timepicker(3219): On Touch event
05-26 09:45:58.007: D/Timepicker(3219): out of getTimePicker return false
05-26 09:45:58.027: D/Timepicker(3219): On Touch event
05-26 09:45:58.027: D/Timepicker(3219): out of getTimePicker return false
05-26 09:45:58.077: D/Timepicker(3219): On Touch event
05-26 09:45:58.077: D/Timepicker(3219): Motion event UP
05-26 09:45:58.077: D/Timepicker(3219): New timepickerdialog instance
05-26 09:45:58.167: D/Timepicker(3219): Timepicker title set
05-26 09:45:58.177: D/Timepicker(3219): Timepicker show()
05-26 09:45:58.187: D/Timepicker(3219): out of getTimePicker return true
05-26 09:46:05.745: D/Timepicker(3219): Ok called
05-26 09:46:05.745: D/Timepicker(3219): OnTimeSet called

OnTimeSet() 在我单击 OK 按钮后立即被调用。

与三星设备相反:

05-26 09:47:59.500: D/Timepicker(12897): Attaching timepicker
05-26 09:47:59.500: D/Timepicker(12897): Inside getTimePicker()
05-26 09:48:01.105: D/Timepicker(12897): On Touch event
05-26 09:48:01.105: D/Timepicker(12897): out of getTimePicker return false
05-26 09:48:01.125: D/Timepicker(12897): On Touch event
05-26 09:48:01.125: D/Timepicker(12897): out of getTimePicker return false
05-26 09:48:01.160: D/Timepicker(12897): On Touch event
05-26 09:48:01.160: D/Timepicker(12897): out of getTimePicker return false
05-26 09:48:01.190: D/Timepicker(12897): On Touch event
05-26 09:48:01.190: D/Timepicker(12897): Motion event UP
05-26 09:48:01.190: D/Timepicker(12897): New timepickerdialog instance
05-26 09:48:01.230: D/Timepicker(12897): Timepicker title set
05-26 09:48:01.230: D/Timepicker(12897): Timepicker show()
05-26 09:48:01.245: D/Timepicker(12897): out of getTimePicker return true
05-26 09:48:04.700: D/Timepicker(12897): Ok called

On timeset 永远不会被调用

我应该怎么做才能使我的代码与三星设备兼容?

最佳答案

我遇到了类似的问题:

onTimeSet 是从我的 nexus VDM 调用的,而不是从 Samsung GS3 调用的。两者都有android 4.3。 This answer helped me to work through the problem.

关于android - 时间选择器对话框 : onTimeSet never called on samsung devices with touchwiz,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com