Problem getting Next Week value in android click button

I want to get the value of next week by pressing a button, so below is my code

OnCreate Method I declare a Calender object and print the current date

    int WeekNumber;
    Calendar mCalendar = Calendar.getInstance();
    mCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    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);
    mTextView.setText(printDate + " >> " + printDate2);

Next Button Click

mButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            WeekNumber++;
            String ss=getNextWeek(WeekNumber);
            System.out.println("ss "+ss);
            mTextView.setText(ss);
        }
    });

getNextWeek () method code

public static String getNextWeek(int weekFromToday) {
    System.out.println("Pass Wee "+weekFromToday);
    Calendar mCalendar =  Calendar.getInstance();
    mCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    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;        
}

When I run a code over the current current week, for example, like 02 Febuarry >> 08 Febuary, but when I click the next button, it prints the wrong week value, for example 23 March >> 29 March, so any idea how I can solve it?

+3
source share
1 answer

I got the solution in y code i initialize weekNumber value as

WeekNumber=mCalendar.get(Calendar.WEEK_OF_YEAR);

so I just comment on the above line, and the rest of the code as it is, and it works fine for me.

+2
source

All Articles