我的活动中有4个按钮,所有按钮都有相同的动作。所以我在Xml中定义了点击。按钮点击应该打开日期选择器对话框。但是我的日期选择器只在我三星点击两次后打开 S2(Android 4.0.4)。但所有其他设备的工作正常。
1.Samsung Star 4.1
2.Videocon 2.3
XML onclick声明
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:onClick="AddTime"
/>
活动中的AddTime方法
public void AddTime(View v)
{
Log.e("Test", "Button Clicked");//On evey click I am getting this log
showDialog(1);//The method showDialog(int) from the type Activity is deprecated
}
@Override
protected Dialog onCreateDialog(int id) {
return new TimePickerDialog(this, timePickerListener, hour, minute,false);
}
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker arg0, int hourofDay, int min) {
// TODO Auto-generated method stub
hour=hourofDay;
minute=min;
String _24HourTime;
}
};
答案 0 :(得分:1)
由于showDialog
是deprecated
,您无法真正依赖它,我建议您直接从方法创建对话框。
public void showTimePickerDialog()
{
TimePickerDialog s4 = new TimePickerDialog(this, null, 1, 1,false);
s4.show();
}
并在onClick
方法
public void AddTime(View v)
{
showTimePickerDialog();
}