我已经成功制作了一个datepicker对话框,并在我的一个标签中添加了。但我想要实现的是选项卡中的选项卡,该选项卡的内容是我的日期选择器。问题是它崩溃了。
所以基本上我想要实现的就像这样
TAB1 _
|
tab2 (found inside tab1)_
|
Datepicker
logcat报告
02-03 18:49:47.063: E/AndroidRuntime(1651): FATAL EXCEPTION: main
02-03 18:49:47.063: E/AndroidRuntime(1651): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@53238480 is not valid; is your activity running?
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.view.ViewRootImpl.setView(ViewRootImpl.java:567)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.app.Dialog.show(Dialog.java:281)
02-03 18:49:47.063: E/AndroidRuntime(1651): at com.example.androidtablayout.$1.onClick(Act.java:111)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.view.View.performClick(View.java:4204)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.view.View$PerformClick.run(View.java:17355)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.os.Handler.handleCallback(Handler.java:725)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.os.Handler.dispatchMessage(Handler.java:92)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.os.Looper.loop(Looper.java:137)
02-03 18:49:47.063: E/AndroidRuntime(1651): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-03 18:49:47.063: E/AndroidRuntime(1651): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 18:49:47.063: E/AndroidRuntime(1651): at java.lang.reflect.Method.invoke(Method.java:511)
02-03 18:49:47.063: E/AndroidRuntime(1651): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-03 18:49:47.063: E/AndroidRuntime(1651): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-03 18:49:47.063: E/AndroidRuntime(1651): at dalvik.system.NativeStart.main(Native Method)
02-03 18:49:47.071: W/ActivityManager(475): Force finishing activity com.example.androidtablayout/.AndroidTabLayoutActivity
datepicker的codenippet
inputDate.setOnClickListener(new OnClickListener() {
public void onClick(View view)
{
int mYear, mMonth, mDay;
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dpd = new DatePickerDialog(Act.this,
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int month, int day) {
c.set(year, month, day);
String date = new SimpleDateFormat("yyyy/MM/dd").format(c.getTime());
inputStart.setText(date);
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
}
}, mYear, mMonth, mDay);
dpd.show();
}
});