android - Listview item deleting last item id -


logcat:

02-06 00:43:21.981: e/parkid(4374): 120 02-06 00:43:21.982: e/parkid(4374): 122 02-06 00:43:21.984: e/parkid(4374): 146 02-06 00:43:21.986: e/parkid(4374): 148 02-06 00:43:21.990: e/parkid(4374): 149 02-06 00:43:21.992: e/parkid(4374): 150 02-06 00:43:21.994: e/parkid(4374): 151 02-06 00:43:21.996: e/parkid(4374): 152 02-06 00:43:39.137: e/finalparkid(4374): 122 02-06 00:43:40.070: e/response(4374): {"error":false,"message":"the parking spot has been deleted.","data":[]} 02-06 00:43:40.078: d/responseparkid(4374): 152 

mainactivity.java

@override     public int getcount() {         // todo auto-generated method stub         return spotlist.size();     }      @override     public object getitem(int position) {         // todo auto-generated method stub         return position;     }      @override     public long getitemid(int position) {         // todo auto-generated method stub         return position;     }     @override     public view getview(final int position, view convertview,         viewgroup parent) {     view view = convertview;      if (convertview == null) {         holder = new viewholder();         view = minlfater.inflate(r.layout.myspot_list_item, null);          holder.favtitletv = (textview) view                 .findviewbyid(r.id.fav_list_titletv);         holder.favtitle2tv = (textview) view                 .findviewbyid(r.id.fav_list_title1tv);         holder.rating_reviews = (ratingbar) view                 .findviewbyid(r.id.ratingbar);         holder.spot_image = (imageview) view                 .findviewbyid(r.id.spot_list_iv);          holder.favspacetv = (textview) view                 .findviewbyid(r.id.fav_list_spacetv);         holder.favtypetv = (textview) view                 .findviewbyid(r.id.fav_parking_type);          button delbutton = (button) view.findviewbyid(r.id.delbutton);          final myspotsmenumodel modelobj = spotlist.get(position);            delbutton.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                  spotidforvol = modelobj.getparking_spot_id();                   hitdeletelistresponse();                   spotlist.remove(position);                   adapter.notifydatasetchanged();                 toast.maketext(myspotsmenuactivity.this,                         "item deleted", toast.length_short).show();                  finish();                 startactivity(getintent());              }              private void hitdeletelistresponse() {                 final progressdialog dialog = new progressdialog(                         myspotsmenuactivity.this);                 dialog.setmessage("loading...");                 dialog.setcancelable(false);                 dialog.show();               string url = os_myspots_delete_url(spotidforvol, getpassword(getapplicationcontext()));                          log.e("finalparkid", spotidforvol);                  stringrequest request = new stringrequest(request.method.get, url,                         new response.listener<string>() {                              @override                             public void onresponse(string response) {                                 if (response != null) {                                     log.e("response", response);                                     dialog.dismiss();                                      try {                                          jsonobject search_obj = new jsonobject(response);                                         if (search_obj.getstring("error").equals("false")) {                                               log.d("responseparkid",""+parkid);                                              toastshort(myspotsmenuactivity.this,                                                     search_obj.getstring("message"));                                         }                                             else {                                                  toastshort(myspotsmenuactivity.this,                                                         "null");                                             }                                          } catch (jsonexception e) {                                             e.printstacktrace();                                         }                                      } else {                                         dialog.dismiss();                                     }                                 }                             }, new response.errorlistener() {                                  @override                                 public void onerrorresponse(volleyerror error) {                                     if (error != null) {                                         log.e("error", error.tostring());                                         dialog.dismiss();                                     }                                  }                             });                      requestqueue queue = volley.newrequestqueue(myspotsmenuactivity.this);                     queue.add(request);                     queue.getcache().remove(url);              }         });            view.settag(holder);     } else {         holder = (viewholder) view.gettag();     }      holder.favtitletv.settext(spotlist.get(position)             .getparking_spot_title());     // holder.favtitle2tv     // .settext(list.get(position).getparking_desc());     holder.favtitle2tv.settext(spotlist.get(position)             .getparking_spot_note());     holder.favspacetv.settext(spotlist.get(position)             .getparking_spot_space());     holder.favtypetv.settext(spotlist.get(position)             .getparking_spot_type());      imageloader.displayimage(spotlist.get(position).getimage(),             holder.spot_image);      return view; }  class viewholder {         textview favaddbtn, favremovebtn;         textview favtitletv, favtitle2tv, favaddrtv, favspacetv, favtypetv;         ratingbar rating_reviews;         imageview spot_image;     } 

i hitting response delete.i'm getting response success message.my issue is,the top 4 listview items delete appropriate id.but if scroll down , delete list item means took last response id.anyone can me this.

use 2 methods achieve position of selected item arraylist.

place code after getview method

@override public int getcount() {     return arraylistobj.size(); }  @override public offer getitem(int position) {     return arraylistobj.get(position); } 

here offer bean class .you can use class name here


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -