问题描述
我是android的一个新手,苦苦挣扎如何将这两个日期选择器
和时间选择器
添加到一个单个对话框
请指导我如何创建一个对话框
并使用功能 setview
对其进行充气,但我遇到了例外情况
i an new in android and struggling with how can i add these two date picker
and time picker
in a single dialog box
please guide me how can i do it i created a dialog box
and use a function setview
to inflate it but i got the exception
AlertDialog.Builder dialog = new AlertDialog.Builder(
MainActivity.this);
dialog.setTitle("Begning");
dialog.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
}
});
dialog.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
View pickers=getLayoutInflater().inflate(R.id.linearLayout1,
null);
dialog.setView(picker);
dialog.show();
}
});
上面是我的代码
,听到的是xml文件
above is my codeand hear is the xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</DatePicker>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TimePicker>
我想创建这样的东西,请帮助我
i want to create something like this please help me
10-06 15:49:24.261: E/Trace(9287): error opening trace file: No such file or directory (2)
10-06 15:49:27.434: W/dalvikvm(9287): threadid=1: thread exiting with uncaught exception (group=0x411903a8)
10-06 15:49:27.454: E/AndroidRuntime(9287): FATAL EXCEPTION: main
10-06 15:49:27.454: E/AndroidRuntime(9287): android.content.res.Resources$NotFoundException: Resource ID #0x7f080000 type #0x12 is not valid
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2150)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.content.res.Resources.getLayout(Resources.java:860)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-06 15:49:27.454: E/AndroidRuntime(9287): at com.example.datetimedialog.MainActivity$1.onClick(MainActivity.java:51)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.view.View.performClick(View.java:4102)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.view.View$PerformClick.run(View.java:17085)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.os.Handler.handleCallback(Handler.java:615)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.os.Handler.dispatchMessage(Handler.java:92)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.os.Looper.loop(Looper.java:155)
10-06 15:49:27.454: E/AndroidRuntime(9287): at android.app.ActivityThread.main(ActivityThread.java:5520)
10-06 15:49:27.454: E/AndroidRuntime(9287): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 15:49:27.454: E/AndroidRuntime(9287): at java.lang.reflect.Method.invoke(Method.java:511)
10-06 15:49:27.454: E/AndroidRuntime(9287): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1058)
10-06 15:49:27.454: E/AndroidRuntime(9287): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:825)
10-06 15:49:27.454: E/AndroidRuntime(9287): at dalvik.system.NativeStart.main(Native Method)
这是 logcat
推荐答案
我在github上创建了一个项目为了这。我采用了与您不同的方法,并通过扩展对话框类创建了具有日期和时间选择器的自定义对话框。
I have created a project on github for this. I have taken a different approach than yours and have created the custom dialog with date and time picker, by extending the dialog class.
这篇关于如何将日期和时间选择器放在android的对话框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!