android - How to update a method on a Button click? -


my code updates calender 1 time when button clicked .it doesn't update calender when button clicked again.i want update dates in weekly basis.below code , logcat,

 public class mycalendar extends activity {  public final static string[] monthcalender = { "january", "february",         "march", "april", "may", "june", "july", "august", "september",         "october", "november", "december" };  public final static int daysinmonths[] = { 31, 28, 31, 30, 31, 30, 31, 31,          30, 31, 30, 31 };  int mon, yr; int j=0; calendar todaycldr;  // mycalendar moncldr = new mycalendar();  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_calendar);      button button1 = (button) findviewbyid(r.id.button1);     //      if (mon == 2) {   //        displaymonth(integer.parseint(args[0]) - 1, //       integer.parseint(args[1]));  //      } else {      todaycldr = calendar.getinstance(); displaymonth(todaycldr.get(calendar.month), todaycldr.get(calendar.year));     // }       button1.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             j=7;             displaymonth(todaycldr.get(calendar.month),      todaycldr.get(calendar.year));          }     });  }  private void displaymonth(int month, int year) {      // number of days leave blank @     // start of month.      int blankdays = 0;     system.out.println("  " + monthcalender[month] + " " + year);      if (month < 0 || month > 11) {         throw new illegalargumentexception("month " + month                 + " not valid , must lie in between 0 ,      11");     }      gregoriancalendar cldr = new gregoriancalendar(year, month, 1);     system.out             .println("sunday monday tuesday wednesday thursday friday    saturday");      // compute how leave before before first day of month.     // getday() returns 0 sunday.      blankdays = cldr.get(calendar.day_of_week) - 1;     int daysinmonth = daysinmonths[month];      if (cldr.isleapyear(cldr.get(calendar.year)) && month == 1) {          ++daysinmonth;     }      // blank out labels before 1st day of month     (int = 0; < blankdays; i++) {         system.out.print("   ");     }      (int = 1; <= daysinmonth; i++) {          // "if" statement simpler messing numberformat         if (i <= 9) {             system.out.print(" ");         }         system.out.print(i+j);          if ((blankdays + i) % 7 == 0) { // wrap if eol             system.out.println();         } else {             system.out.print(" ");         }         if (i % 7 ==0)         {             break;         }     } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.activity_calendar, menu);     return true; }     } 

logcat

    09-04 01:00:37.727: i/system.out(591):   september 2013    : sunday monday tuesday wednesday thursday friday saturday      1  2  3  4  5  6  7          september 2013  system.out(591): sunday monday tuesday wednesday thursday friday saturday      system.out(591):  8  9  10  11  12  13  14  i/system.out(591):   september 2013  : i/system.out(591): sunday monday tuesday wednesday thursday friday saturday  i/system.out(591):  8  9  10  11  12  13  14  i/system.out(591):   september 2013   i/system.out(591): sunday monday tuesday wednesday thursday friday saturday  09-04 01:01:20.017: i/system.out(591):  8  9  10  11  12  13  14 

any suggestion highly appreciated.thanks.

create constructor , move code in it:

public mycalendar() {         // todo auto-generated constructor stub         todaycldr = calendar.getinstance();             year = todaycldr.get(calendar.year);     monthofyear = todaycldr.get(calendar.month);       } 

and call displaymonth in oncreate:

displaymonth(monthofyear, year); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -