android - Issue in getView() Of BaseAdapter For GridView -


enter image description here

i creating calender app. in user should enter events. events stored in local database. have created baseadapter class. in baseadapters getview() method happened cant understand. please see screen shot have attached here. in screen find calender. @ right bottom side call see white-gray colored plus button. when user press button in calender's grid view grid shells display green colored small plus sign. done in baseadapters getview() method.

please see code here :

package com.examples;  import java.lang.reflect.array; import java.text.parseexception; import java.text.simpledateformat; import java.util.arraylist; import java.util.calendar; import java.util.date; import java.util.gregoriancalendar; import java.util.hashmap; import java.util.iterator; import java.util.list; import android.r.integer; import android.content.context; import android.content.sharedpreferences; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.graphics.color; import android.text.format.dateformat; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.view.view.onclicklistener; import android.widget.baseadapter; import android.widget.button; import android.widget.imagebutton; import android.widget.textview; import android.widget.toast;  public class gridcelladapter extends baseadapter{     private final context _context;     private final list<string> list;     private static final int day_offset = 1;     private final string[] weekdays = new string[]{"sun", "mon", "tue", "wed", "thu", "fri", "sat"};     private final string[] months = {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"};     private final int[] daysofmonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};     private final int month, year;     private int daysinmonth, prevmonthdays;     private int currentdayofmonth;     private int currentweekday;     private textview num_events_per_day;     private final hashmap eventspermonthmap;     private final simpledateformat dateformatter = new simpledateformat("dd-mmm-yyyy");     boolean token; //  boolean boo;     layoutinflater inflater;     arraylist<string> arrlst;     private sharedpreferences prefs;     private string prefname = "mypref"; //  list<string> list_selected = new arraylist<string>();     string clicked_day;     boolean personla_token;     dbadapter db;      public gridcelladapter(context context, int textviewresourceid, int month, int year, boolean token)     {         super();         this._context = context;         this.list = new arraylist<string>();         this.month = month;         this.year = year;         this.token = token;         db = new dbadapter(context);         arrlst = new arraylist<string>(); //      list_selected = new arraylist<string>();         log.v("","adapter token : "+token);         calendar calendar = calendar.getinstance();         prefs = context.getsharedpreferences(prefname, context.mode_private); //      log.v("","check preference : "+prefs.getstring("textvalue", ""));         setcurrentdayofmonth(calendar.get(calendar.day_of_month));         setcurrentweekday(calendar.get(calendar.day_of_week));         // print month         printmonth(month, year);         dbadapter db;          // find number of events         eventspermonthmap = findnumberofeventspermonth(year, month);         inflater = layoutinflater.from(context);      }      private string getmonthasstring(int i)     {         return months[i];     }      private string getweekdayasstring(int i)     {         return weekdays[i];     }      private int getnumberofdaysofmonth(int i)     {         return daysofmonth[i];     }      public string getitem(int position)     {         return list.get(position);     }      @override     public int getcount()     { //      log.v("","list size : "+list.size());         return list.size();     }      private void printmonth(int mm, int yy)     {         // number of days leave blank @         // start of month.         int trailingspaces = 0;         int leadspaces = 0;         int daysinprevmonth = 0;         int prevmonth = 0;         int prevyear = 0;         int nextmonth = 0;         int nextyear = 0;          int currentmonth = mm - 1; //      log.v("","current month printmonth : "+currentmonth);         string currentmonthname = getmonthasstring(currentmonth); //      log.v("","this month in string : "+currentmonthname);         daysinmonth = getnumberofdaysofmonth(currentmonth);           // gregorian calendar : minus 1, set first of month         gregoriancalendar cal = new gregoriancalendar(yy, currentmonth, 1);          if (currentmonth == 11)         {             prevmonth = currentmonth - 1;             daysinprevmonth = getnumberofdaysofmonth(prevmonth);             nextmonth = 0;             prevyear = yy;             nextyear = yy + 1;         }         else if (currentmonth == 0)         {             prevmonth = 11;             prevyear = yy - 1;             nextyear = yy;             daysinprevmonth = getnumberofdaysofmonth(prevmonth);             nextmonth = 1; //          log.d(tag, "**--> prevyear: " + prevyear + " prevmonth:" + prevmonth + " nextmonth: " + nextmonth + " nextyear: " + nextyear);         }         else         {             prevmonth = currentmonth - 1;             nextmonth = currentmonth + 1;             nextyear = yy;             prevyear = yy;             daysinprevmonth = getnumberofdaysofmonth(prevmonth); //          log.v(tag, "***---> prevyear: " + prevyear + " prevmonth:" + prevmonth + " nextmonth: " + nextmonth + " nextyear: " + nextyear);         }         // compute how leave before before first day of         // month.         // getday() returns 0 sunday.         int currentweekday = cal.get(calendar.day_of_week) - 1;         trailingspaces = currentweekday;  //      log.v("","current week days : "+currentweekday); //      log.v("","trailing spaces : "+trailingspaces);         if (cal.isleapyear(cal.get(calendar.year)) && mm == 1)         {             ++daysinmonth;         }          // trailing month days         (int = 0; < trailingspaces; i++)         { //              log.d(tag, "prev month:= " + prevmonth + " => " + getmonthasstring(prevmonth) + " " + string.valueof((daysinprevmonth - trailingspaces + day_offset) + i));             list.add(string.valueof((daysinprevmonth - trailingspaces + day_offset) + i) + "-grey" + "-" + getmonthasstring(prevmonth) + "-" + prevyear);         }          // current month days         (int = 1; <= daysinmonth; i++)         { //              log.d(currentmonthname, string.valueof(i) + " " + getmonthasstring(currentmonth) + " " + yy);             if (i == getcurrentdayofmonth())             {                 list.add(string.valueof(i) + "-blue" + "-" + getmonthasstring(currentmonth) + "-" + yy);             }             else             {                 list.add(string.valueof(i) + "-white" + "-" + getmonthasstring(currentmonth) + "-" + yy);             }         }          // leading month days         (int = 0; < list.size() % 7; i++)         { //              log.d(tag, "next month:= " + getmonthasstring(nextmonth));             list.add(string.valueof(i + 1) + "-grey" + "-" + getmonthasstring(nextmonth) + "-" + nextyear);         }     }      /**      * note: need implement part given year, month, retrieve      * entries sqlite database month. iterate on      * list of entries, , datecreated, converted      * day.      *       * @param year      * @param month      * @return      */     private hashmap findnumberofeventspermonth(int year, int month)          {             hashmap map = new hashmap<string, integer>();              dateformat dateformatter2 = new dateformat();             //                                   // string day = dateformatter2.format("dd", datecreated).tostring();             //             // if (map.containskey(day))             // {             // integer val = (integer) map.get(day) + 1;             // map.put(day, val);             // }             // else             // {             // map.put(day, 1);             // }             return map;         }     @override     public long getitemid(int position)     {         return position;     }     string full_date;     @override     public view getview(int position, view convertview, viewgroup parent)     {         viewholder holder = null;            if (convertview == null){             holder= new viewholder();             convertview = inflater.inflate(r.layout.calendar_day_gridcell, null);              holder.gridcell = (button) convertview.findviewbyid(r.id.calendar_day_gridcell);             holder.btn_img_plus_internal = (imagebutton)convertview.findviewbyid(r.id.btn_plus_green);              convertview.settag(holder);         }         else{             holder = (viewholder) convertview.gettag();         }          // reference day gridcell          // account spacing          string[] day_color = list.get(position).split("-");         string theday   = day_color[0];         string themonth = day_color[2];         string theyear  = day_color[3];          full_date = theday+"-"+themonth+"-"+theyear;          //check everytime when gridcell created if date inside database replce image specific entry          db.open();         cursor c = db.getalldata();         if(c.movetofirst()){             {                 if(full_date.equals(c.getstring(1))){                     holder.btn_img_plus_internal.setvisibility(view.visible);                         holder.btn_img_plus_internal.setbackgroundresource(r.drawable.event_3);                 }             } while (c.movetonext());         }          c.close();         db.close();          if(token){             holder.btn_img_plus_internal.setvisibility(view.visible);         }          holder.btn_img_plus_internal.settag(full_date);         holder.btn_img_plus_internal.setonclicklistener(new onclicklistener() {             @override             public void onclick(view v) {                 // todo auto-generated method stub                 clicked_day = (string) v.gettag();                      db.open();                         db.insert(clicked_day, prefs.getstring("textvalue", ""));                     db.close();                     notifydatasetchanged();             }         });          // set day gridcell         holder.gridcell.settext(theday);         return convertview;     }      public int getcurrentdayofmonth()     {         return currentdayofmonth;     }     private void setcurrentdayofmonth(int currentdayofmonth)     {         this.currentdayofmonth = currentdayofmonth;     }     public void setcurrentweekday(int currentweekday)     {         this.currentweekday = currentweekday;     }     public int getcurrentweekday()     {         return currentweekday;     }      public class viewholder{         button gridcell;         imagebutton btn_img_plus_internal;     } } 

now inside getview() method can see when user press small-green-plus button inside grid shell date stored in local database. , in

holder.btn_img_plus_internal.setonclicklistener(new onclicklistener() {  

i have call method notifydatasetchanged(); that's why again getview() called , data local database fetched , make here different image. , done when click green-small-plus button image replaced attached image. when press image second time there other images other grid replaced too.

for example when first time pressed 15 dated greed green-plus image replaced once press it. want. when press after example 12 dated image replaced other image too. want when press particulate green-plus image image want replaced. , last image pressed should before keep replaced there. have add link here after make video of android app. please see these video : http://fortunemobiletech.comyr.com/ccc/calender_android_app.swf please give me replay proper solutions. thank in advance


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -