显示了一个月的日子, [英] Displaying all the days of a month

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

问题描述

在我的应用程序,当用户选择查看当前月份的细节,一个新的屏幕将打开。在这个屏幕上,我们将有一个下拉菜单。在下拉菜单中我想显示当月的所有日期。这样他就可以选择日期,他感兴趣。

In my application, when the user selects to view the details of the current month, a new screen will open. In that screen, we will have a drop down menu. In the drop down menu I want to display all the dates of that month. So that he can select the date he is interested in.

例如,如果当前的月份是二月,然后下拉菜单包含28号(有时是29)。

For example, if the current month is Feb, then drop down menu is expected to contain 28 numbers( sometimes 29).

我已经使用XML布局在我的应用程序。

I have used xml layout in my app.

任何人都可以给我建议,实施这个更好的方法...?

Could anyone suggest me a better way of implementing this...?

推荐答案

尝试使用的DatePicker ...

Try using DatePicker...

下面是示例code ..

here is the sample code..

写的..

static final int DATE_DIALOG_ID = 0;

@Override
    protected Dialog onCreateDialog(int id) {
        Calendar c = Calendar.getInstance();
        int cyear = c.get(Calendar.YEAR);
        int cmonth = c.get(Calendar.MONTH);
        int cday = c.get(Calendar.DAY_OF_MONTH);
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this, mDateSetListener, cyear, cmonth,
                    cday);
        }
        return null;
    }

    private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
        // onDateSet method
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                int dayOfMonth) { 
            String date_selected = String.valueOf(dayOfMonth) + " - "
                    + String.valueOf(monthOfYear + 1) + " - "
                    + String.valueOf(year);
             Toast.makeText(getApplicationContext(), "Selected Date is =" +   date_selected, Toast.LENGTH_SHORT).show();

        }
    };

,每当你想要显示的日期选择器调用此。

and call this whenever you want to display the Datepicker..

showDialog(DATE_DIALOG_ID);

这将显示一个漂亮的DatePicker,您可以从中选择一个日期......

That displays a nice DatePicker from which you can select a date....

这篇关于显示了一个月的日子,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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