android - Issue on Changing the image in ListView -


i writing android application list item database, , mark of item favorite , keep update database according favorite.

my aim is:

when mark particular item of listview favorite, image of particular list item changed , corresponding column of table should updated favorite(yes) or not favorite(no).

it working fine list item database, change image source according favorite, update database also.

my problem is:

1.when press image of particular item, image changed once, , corresponding database changed. but, clicking on same image another time(last time clicked image) does not change anything(not change image , not update).

2.by scrolling listview keep listview before changing listview.

i refer this link, before use database. working fine.

after use database, changed code below:

public class episodecursoradapter extends simplecursoradapter {      public final string tag = "episodecursoradapter";     //private string strurl = "http://timesofindia.feedsportal.com/c/33039/f/533916/index.rss";     public int favourite[];     private cursor c,temp_cursor;     private context context;     aabdatabasemanager db;     public episodecursoradapter(context context, int layout, cursor c,             string[] from, int[] to) {         super(context, layout, c, from, to);         this.c = c;         temp_cursor=c;         this.context = context;         log.d(tag, "object size is:" +c.getcount()); //      favourite = new int[c.getcount()]; //      (int = 0; < c.getcount(); i++) { //          favourite[i] = 0; //      }     }      static class episodeholder {         textview title;         textview desc;         imageview thumbnail, favourite;     }      @override     public view newview(context context, cursor cursor, viewgroup parent) {         log.d(tag,"new view in cursor adapater"+"  "+cursor.getcount());         cursor cc=getcursor();         log.d(tag,"new view in cursor adapater"+"  "+cc.getcount()+ "   "+cc.getint(0));          // todo auto-generated method stub         return super.newview(context, cursor, parent);     }     public view getview(final int pos, view inview, viewgroup parent) {           log.d(tag,"getview view in cursor adapater " + pos);         view v = inview;         if (v == null) {             layoutinflater inflater = (layoutinflater) context                     .getsystemservice(context.layout_inflater_service);             v = inflater.inflate(r.layout.episode_row_view, null);             final episodeholder holder = new episodeholder();             db =  new aabdatabasemanager(context);             holder.title = (textview) v.findviewbyid(r.id.title);             holder.desc = (textview) v.findviewbyid(r.id.description);             holder.favourite = (imageview) v.findviewbyid(r.id.imageview1);             holder.thumbnail = (imageview) v.findviewbyid(r.id.image);             v.settag(holder);             log.d(tag, "row tag is:" + v.gettag());             holder.favourite.settag(pos);                holder.favourite.setonclicklistener(new view.onclicklistener() {                  @override                 public void onclick(view v) {                      int posi = (integer) v.gettag();                     //log.d(tag, "cursor total count" + c.getcount() + "   position:" + holder.favourite.gettag() + "    view position:" + pos + " " + posi);                     log.d(tag,"****************************** info regarding clicking on favourite ************************");                     log.d(tag,"position of image clicked          : " + posi);                     temp_cursor.movetoposition(posi);                     int id = temp_cursor.getint(temp_cursor.getcolumnindex("_id"));                     string markedasfav = temp_cursor.getstring(temp_cursor.getcolumnindex("favourite"));                     log.d(tag, "id of clicked item : " + id + "             favourite : " + markedasfav);                      if(markedasfav.equalsignorecase("no")) {                          log.d(tag, "****in favourite onclick*** not favourite... mark favourite...");                         holder.favourite.setimageresource(r.drawable.ic_favourite_2);                         db.updaterowasfav(id, temp_cursor.getstring(temp_cursor.getcolumnindex("favourite")));                     } else if(markedasfav.equalsignorecase("yes")) {                         log.d(tag, "****in favourite onclick*** favourite... mark not favourite...");                         holder.favourite.setimageresource(r.drawable.ic_favourite_1);                         db.updaterowasfav(id, temp_cursor.getstring(temp_cursor.getcolumnindex("favourite")));                     }                 }             });         } else {             ((episodeholder) v.gettag()).favourite.settag(pos);         }         final episodeholder holder = (episodeholder) v.gettag();         this.c.movetoposition(pos);         string imageurl = this.c.getstring(this.c                 .getcolumnindex("table_epi_image"));         string titlestr = this.c.getstring(this.c                 .getcolumnindex("table_epi_title"));         string descstr = this.c.getstring(this.c                 .getcolumnindex("table_epi_description"));          if(c.getstring(c.getcolumnindex("favourite")).equalsignorecase("yes"))                 {             holder.favourite.setimageresource(r.drawable.ic_favourite_2);                 }         else         {             holder.favourite.setimageresource(r.drawable.ic_favourite_1);          }          holder.thumbnail.settag(imageurl);         new downloadimagestask().execute(holder.thumbnail);          //textview title = (textview) v.findviewbyid(r.id.title);         holder.title.settext(titlestr);          //textview desc = (textview) v.findviewbyid(r.id.description);         holder.desc.settext(descstr);         return (v);     }  } 

i know missing something. couldn't find out that.

please me solve this.

thank in advance!

as yume117 said, have called notifydatasetchanged() method. have updated answer below:

i have added line refreshcursoradapter(); next below codes in onclick()

if(markedasfav.equalsignorecase("no")) {                          log.d(tag, "****in favourite onclick*** not favourite... mark favourite...");                         holder.favourite.setimageresource(r.drawable.ic_favourite_2);                         db.updaterowasfav(id, temp_cursor.getstring(temp_cursor.getcolumnindex("favourite")));                     } else if(markedasfav.equalsignorecase("yes")) {                         log.d(tag, "****in favourite onclick*** favourite... mark not favourite...");                         holder.favourite.setimageresource(r.drawable.ic_favourite_1);                         db.updaterowasfav(id, temp_cursor.getstring(temp_cursor.getcolumnindex("favourite")));                     } 

refreshcursoradapter is:

public void refreshcursoradapter() {         // todo auto-generated method stub          log.d(tag,"refresh adapter called....***************");         dbadapter = new dbadapter();         cursor cursor = null;         try {             episodecursoradapter adapter;             dbadapter.open();             cursor = dbadapter.fetchlimitrowsfromepisode(                     common.currentlistcountforepi, episodeactivity.refid);             string[] columns = new string[] { databasehelper.sub_id,                     databasehelper.epi_fileimage_id,                     databasehelper.epi_title, databasehelper.epi_desc };              // xml defined views data bound             int[] = new int[] { r.id.title, r.id.description };             adapter = new episodecursoradapter(                     episodeactivity.context, r.layout.episode_row_view,                     cursor, columns, to, common.refresh);              adapter.changecursor(cursor);             adapter.notifydatasetchanged();              dbadapter.close();         } catch (exception e) {             e.printstacktrace();         }      } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -