java - Attempting to update ListView Items -


i working on listview starts off containing 4 items: event a, event b, event c, , event d.

these 4 events stored in arraylist<event> called mevents , on button click filter out event b arraylist , update listview accordingly through adapter using notifydatasetchanged().

i using second arraylist<event> named newevents store events should displayed (event a/c/d) , clear mevents , set equal newevents.

when button pressed, reason last list item gets deleted (event d) regardless of event attempt filter out.

below relevant code, appreciated.

listview code:

public class listactivity extends fragmentactivity {  private usercustomfilters musercustomfilters = new usercustomfilters();  // our database hostname , credentials string url = ; // string user = ; string pass =;  sqlutils sqlu ; //the sqlutil object type initialized later depending on credentials given above. arraylist<event> mevents;       //the array hold events pass around(to adapter,the list...) list<event> even;  //change static if intent used refresh arraylist<event> newevent =new arraylist<>(); listviewadapter adapter;  //default constructor class listactivity public listactivity() {     sqlu = new sqlutils(url, user, pass); //creating object type sqlutils using credentials needed     = sqlu.events();  //imports list of events database.      mevents = new arraylist<>();  //assigning new array events go.      //setting new array.     for(int i=0;i<even.size();i++)     {         mevents.add(even.get(i));     } }  //injecting buttons using butterknife library @injectview(android.r.id.list) listview mlistview;  private void setupfilters(){      // calling filterview class set layout filters      filterview filterview = new filterview(this);     musercustomfilters = filterview.init(); }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_list2);      setupfilters();      adapter=new listviewadapter(this, mevents);       mlistview.setadapter(adapter);      //swipe stuff     adapter.setmode(attributes.mode.single); }  ..........  @onclick(r.id.filtersavebutton) public void implementingbutton(view view)  {      for(int =0; i< mevents.size();i++){          if(mevents.get(i).geteventname().equals("event b")){          }         else{             newevent.add(mevents.get(i));         }     }      adapter.getdata().clear();      adapter.getdata().addall(newevent);      adapter.notifydatasetchanged();  } 

}

listviewadapter code:

public class listviewadapter extends baseswipeadapter {  private activity mactivity; private arraylist<event> mevents; public static int clicks=0;  //the constructor class. public listviewadapter(activity activity, arraylist<event> events) {     mactivity = activity;     mevents = events; }  @override public int getcount() {     return mevents.size();  //returns length of array of events }  @override public object getitem(int position) {     return mevents.get(position);  //returns item being accessed in the array} }  @override public long getitemid(int position) {     return 0;   //id of item being accessed in view }  public arraylist<event> getdata() {      return mevents; }  @override public int getswipelayoutresourceid(int i) {     return r.id.swipe; }  @override public view generateview(int position, viewgroup parent) {      //inflates view used     view convertview = layoutinflater.from(mactivity).inflate(r.layout.list_item, parent, false);      viewholder holder = new viewholder(); //making variable of class type viewholder def      convertview.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             //assigning relative layout contains detailed description.             relativelayout layout = (relativelayout) v.findviewbyid(r.id.descriptionlayout);              //assigning summary description stuff hide , reappear depending on clicks.             imageview bubble = (imageview) v.findviewbyid(r.id.eventimagebubble);              textview eventname = (textview) v.findviewbyid(r.id.texteventname);             textview eventdate = (textview) v.findviewbyid(r.id.texteventdate);             textview eventprice = (textview) v.findviewbyid(r.id.texteventprice);             textview eventdistance = (textview) v.findviewbyid(r.id.texteventdistance);              if (clicks % 2 == 0) {                 //popping detailed description view.                 layout.setvisibility(view.visible);                  //hiding summary description view display detailed description.                 bubble.setvisibility(view.invisible);                 eventname.setvisibility(view.invisible);                 eventdate.setvisibility(view.invisible);                 eventprice.setvisibility(view.invisible);                 eventdistance.setvisibility(view.invisible);             } else {                 //hiding detailed description upon 2nd click.                 layout.setvisibility(view.invisible);                  //displaying summary description upon 2nd click.                 bubble.setvisibility(view.visible);                 eventname.setvisibility(view.visible);                 eventdate.setvisibility(view.visible);                 eventprice.setvisibility(view.visible);                 eventdistance.setvisibility(view.visible);             }              clicks++; //adds number of times user has tapped on item.         }     });      convertview.settag(holder); //sets tag      //summary description of events.     holder.eventpicture= (imageview) convertview.findviewbyid(r.id.imageeventpicture);     holder.eventicon = (imageview) convertview.findviewbyid(r.id.imageeventicon);     holder.eventname = (textview) convertview.findviewbyid(r.id.texteventname);     holder.eventdate = (textview) convertview.findviewbyid(r.id.texteventdate);     holder.eventprice= (textview) convertview.findviewbyid(r.id.texteventprice);     holder.eventdistance= (textview) convertview.findviewbyid(r.id.texteventdistance);      //initializing each item required type     event event = mevents.get(position);      //detailed description of events.     holder.eventdname=(textview) convertview.findviewbyid(r.id.deseventname);     holder.eventdprice= (textview) convertview.findviewbyid(r.id.deseventprice);     holder.eventlocname=(textview) convertview.findviewbyid(r.id.deseventlocname);     holder.eventlocst=(textview) convertview.findviewbyid(r.id.deseventlocstreet);     holder.eventlocadd=(textview) convertview.findviewbyid(r.id.deseventlocaddress);     holder.eventstartdate=(textview) convertview.findviewbyid(r.id.deseventstartdate);     holder.eventstarttime=(textview) convertview.findviewbyid(r.id.deseventstarttime);     holder.eventenddate=(textview) convertview.findviewbyid(r.id.deseventenddate);     holder.eventendtime= (textview) convertview.findviewbyid(r.id.deseventendtime);      //setting text boxes information retrieved arrays of events      //setting summary description     holder.eventdistance.settext(event.geteventdistance()+"km");     holder.eventname.settext(event.geteventname());     holder.eventdate.settext(event.geteventdate());     holder.eventprice.settext("$"+event.geteventprice());     //holder.eventicon.setimageresource(event.geteventicon());     //holder.eventpicture.setimageresource(event.geteventpicture());      //setting detailed description.     holder.eventdname.settext(event.geteventname());     holder.eventdprice.settext("$"+event.geteventprice());     holder.eventlocname.settext(event.geteventlocname());     holder.eventlocst.settext(event.geteventlocst());     holder.eventlocadd.settext(event.geteventlocadd());     holder.eventstartdate.settext(event.geteventdate());     holder.eventstarttime.settext(event.geteventstarttime());     holder.eventenddate.settext(event.geteventenddate());     holder.eventendtime.settext(event.geteventendtime());      //swipe methods being implemented     swipelayout swipelayout = (swipelayout)convertview.findviewbyid(getswipelayoutresourceid(position));      swipelayout.setshowmode(swipelayout.showmode.pullout);      swipelayout.adddrag(swipelayout.dragedge.left, convertview.findviewbyid(r.id.bottom_wrapper));      swipelayout.adddrag(swipelayout.dragedge.right, convertview.findviewbyid(r.id.mlinear));      swipelayout.addswipelistener(new simpleswipelistener() {          @override         public void onopen(swipelayout layout) {          }     });      return convertview; }  @override public void fillvalues(int position, view convertview) {  }  private static class viewholder{     //the values holding summary description of event.     imageview eventpicture;     imageview eventicon;     textview eventname;     textview eventdate;     textview eventprice;     textview eventdistance;      //the values holding detailed description of event.     textview eventdname;     textview eventdprice;     textview eventlocname;     textview eventlocst;     textview eventlocadd;     textview eventstartdate;     textview eventstarttime;     textview eventenddate;     textview eventendtime; } 

}

you using "newevent" instead of "newevent"


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -