AlertDialog用的DatePicker [英] AlertDialog with DatePicker

查看:134
本文介绍了AlertDialog用的DatePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的想法是使用一个AlertDialog并设置到它的一个的DatePicker。结果
我的code是:

My idea is to use an AlertDialog and set to it a a DatePicker.
My code is:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DatePicker picker = new DatePicker(this);
    picker.setCalendarViewShown(false);

    builder.setTitle("Create Year");
    builder.setView(picker);
    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("Set", null);

    builder.show();

它的工作原理,但我的问题是:我怎么能对集听众和取消按钮结果?
关于设置按钮,我想有监听器和(当然)获取用户的日期(他的约会对象选择)搜索结果
结果
我还想显示刚刚年,所以我要隐藏的日和月数据。

it works, but my question is: how can i have the listeners on the set and cancel button?
About the set button i would like to have the listener and (of course) get the date of the user (his date selection)


I want also show just the year so i want to hide the day and month data.

推荐答案

您可以使用 setPositiveButton ,就像这样:

You can use setPositiveButton, like this :

dialog.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int id) {
    //do something         
  }
});

同为 setNegativeButton

我想也只显示一年,所以我要隐藏的日和月
  数据

I want also show just the year so i want to hide the day and month data

看到这,使用第一个答案是:

See this, use the 1st answer :

隐藏领域的年度Android中的DatePicker?

这篇关于AlertDialog用的DatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆