在机器人下周实施机器人、下周

由网友(把孤独当做晚餐)分享简介:在我的样本项目中,我在下周星期一落实到周日在文本视图(如5月6日>> 12我的)。单击下一步按钮,它必须显示下周开始日期和结束日期(如5月13日>> 5月19日)。我已经实现用下面的code中的intial周视图In my sample project i have to implement next week Mo...

在我的样本项目中,我在下周星期一落实到周日在文本视图(如5月6日>> 12我的)。单击下一步按钮,它必须显示下周开始日期和结束日期(如5月13日>> 5月19日)。我已经实现用下面的code中的intial周视图

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为PARAMS ..

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;        
    }

现在declaire静态申请为

Now declaire a static filed as

private static int weekNumber = -1; 

和下面写code按钮点击

and write below code on button click

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

这会工作。

编程快乐:)的

Happy coding :)

阅读全文

相关推荐

最新文章