创建同时包含 TimePicker 和 DatePicker 的对话框时出现问题?
我正在创建一个自定义对话框,我想在其中使用 DatePicker 和 TimePicker 。虽然我可以根据需要使用 TimePicker 但对于 DatePicker 我缺乏想法。 请帮我。 我的代码如下
我的 XML 布局文件是...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TimePicker android:id="@+id/timePicker1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TimePicker>
<DatePicker android:id="@+id/datePicker1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></DatePicker>
<Button android:id="@+id/buttondatetime" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="OK" />
我用于创建自定义对话框的 Java 代码是
void dialogDateTime()
{
dialog = new Dialog(this);
dialog.setContentView(R.layout.datetime);
dialog.setCancelable(true);
dialog.setTitle("This is Dialog 1");
dialog.show();
TimePicker time_picker = (TimePicker) dialog.findViewById(R.id.timePicker1);
time_picker.setOnTimeChangedListener(new OnTimeChangedListener()
{
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minutes)
{
// TODO Auto-generated method stub
}
});
DatePicker date_picker = (DatePicker) dialog.findViewById(R.id.datePicker1);
Button btn_ok = (Button) dialog.findViewById(R.id.buttondatetime);
btn_ok.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
String text = "Time "+hours+":"+minute;
tv_date_time.setText(text);
dialog.cancel();
}
});
}
@Override 受保护的对话框 onCreateDialog(int id) { // TODO 自动生成的方法存根
switch (id)
{
case DIALOG_1:
dialogDateTime();
break;
case DIALOG_2:
dialogTwo();
break;
default:
break;
}
return super.onCreateDialog(id);
}
我没有像 TimePicker 那样获得 DatePicker 的任何方法,所以我无法使用 DatePicker 请帮忙
I am creating a Custom dialog where I want to use both DatePicker and TimePicker .Although I am able to use TimePicker as I want but for DatePicker I am short of ideas.
Please Help Me.
My Code is as follows
My XML Layout file is...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TimePicker android:id="@+id/timePicker1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TimePicker>
<DatePicker android:id="@+id/datePicker1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></DatePicker>
<Button android:id="@+id/buttondatetime" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="OK" />
And My Java Code for Creating Custom Dialog is
void dialogDateTime()
{
dialog = new Dialog(this);
dialog.setContentView(R.layout.datetime);
dialog.setCancelable(true);
dialog.setTitle("This is Dialog 1");
dialog.show();
TimePicker time_picker = (TimePicker) dialog.findViewById(R.id.timePicker1);
time_picker.setOnTimeChangedListener(new OnTimeChangedListener()
{
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minutes)
{
// TODO Auto-generated method stub
}
});
DatePicker date_picker = (DatePicker) dialog.findViewById(R.id.datePicker1);
Button btn_ok = (Button) dialog.findViewById(R.id.buttondatetime);
btn_ok.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
String text = "Time "+hours+":"+minute;
tv_date_time.setText(text);
dialog.cancel();
}
});
}
@Override
protected Dialog onCreateDialog(int id)
{
// TODO Auto-generated method stub
switch (id)
{
case DIALOG_1:
dialogDateTime();
break;
case DIALOG_2:
dialogTwo();
break;
default:
break;
}
return super.onCreateDialog(id);
}
I am not getting any method for DatePicker as in TimePicker So I am not able to use DatePicker
Please Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢您没有回复我自己找到了答案..
我这样改变了我的方法
感谢链接 Android Date和时间控制
Thanks for not replying I found answer on my own ..
I changed my method like this
Thanks to link Android Date and Time Controls