下周在android中实现

Next week implementation in android(下周在android中实现)
本文介绍了下周在android中实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在我的示例项目中,我必须在下周周一至周日在文本视图中实施(如 5 月 6 日 >> 12 My).单击下一个按钮时,它必须显示下周的开始日期和结束日期(如 5 月 13 日 >> 5 月 19 日).我已经使用以下代码实现了初始周视图

In my sample project i have to implement next week Monday to sunday in a text view (like 6 May >> 12 My). on click of next button it must show next week start date and end date (like 13 May >> 19 May). I have implemented the intial week view with the following code

   Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    SimpleDateFormat df = new SimpleDateFormat("dd MMMM");
    String printDate = df.format(c.getTime());
    //gestureEvent.setText(reportDate);
    c.add(Calendar.DAY_OF_WEEK, 6);
    String printDate2 = df2.format(c.getTime());
    gestureEvent.setText(reportDate +" >> "+reportDate2);

点击下周按钮我已经这样做了,但它是静态的,这只是一次尝试:)

on click of next week button i have done this but it static it was just an attempt attempt :)

onclick 会调用这个函数 goNextWeek()

onclick will call this function goNextWeek()

public void goNextWeek()
{

    Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

        c.add(Calendar.DAY_OF_WEEK, 6);
        System.out.println("End Date : " + c.getTime());

        SimpleDateFormat df = new SimpleDateFormat("dd MMMM");
        String reportDate = df.format(c.getTime());
        gestureEvent.setText(reportDate);
        c.add(Calendar.DAY_OF_WEEK, dates);
        c.add(Calendar.DAY_OF_WEEK, 1);
        System.out.println("End Date asdfadf: " + c.getTime()); 


}

请告诉我如何显示下周的开始和结束日期?

please tell me how to show next week start and end date?

推荐答案

这是您的解决方案.

Calendar mCalendar = new GregorianCalendar(); 
        mCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        SimpleDateFormat mDF = new SimpleDateFormat("dd MMMM");
        String printDate = mDF.format(mCalendar.getTime());
        mCalendar.add(Calendar.DAY_OF_MONTH, 6);
        String printDate2 = mDF.format(mCalendar.getTime());

        System.out.println(printDate + " >> " + printDate2);
        gestureEvent.setText(printDate + " >> " + printDate2);

<小时>

按钮实施更新

写一个方法,将weekNumber作为参数..

Write a method, which will take weekNumber as params..

private static String getNextWeek(int weekFromToday) {
        Calendar mCalendar = new GregorianCalendar(); 
        mCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        mCalendar.set(Calendar.WEEK_OF_YEAR, 
                mCalendar.get(Calendar.WEEK_OF_YEAR) + weekFromToday);          

        SimpleDateFormat mDF = new SimpleDateFormat("dd MMMM");
        String printDate = mDF.format(mCalendar.getTime());
        System.out.println(printDate);

        //gestureEvent.setText(reportDate);
        mCalendar.add(Calendar.DAY_OF_MONTH, 6);
        String printDate2 = mDF.format(mCalendar.getTime());
        System.out.println(printDate + " >> " + printDate2);
        return printDate + " >> " + printDate2;        
    }

现在声明一个静态文件为

Now declaire a static filed as

private static int weekNumber = -1; 

并在按钮单击时编写以下代码

and write below code on button click

weekNumber = weekNumber + 1;
gestureEvent.setText(getNextWeek(weekNumber));

这会起作用.

编码愉快 :)

这篇关于下周在android中实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Month is not printed from a date - Java DateFormat(月份不是从日期打印的 - Java DateFormat)
java get week of year for given a date(java获取给定日期的一年中的一周)
Get the number of days, weeks, and months, since Epoch in Java(获取自 Java 中的 Epoch 以来的天数、周数和月数)
Is there a good way to get the date of the coming Wednesday?(有什么好方法可以得到即将到来的星期三的日期吗?)
Calendar view for Android GingerBread and before (APIlt;11)(Android GingerBread 及之前的日历视图 (API11))
How to save and retrieve Date in SharedPreferences(如何在 SharedPreferences 中保存和检索日期)