refresh - Stop listview from updating previous items and only update current items -
i new here. few months started learn android , want create listview , parent & child relationship, when clicking parent value in child value should me modified. did. problem when clicking 1st parent it's working fine while clicking 1 values getting refresh.
my code
//int slno = 1; int rs; int pcount =1; int finalrs; string ip_address, url, tableno, itmename; private string item_name = "itemname"; private string item_price = "price"; int in, totalqut , totalv; string strvalp; //public activity activity; //initialize variables private static final string str_checked = " has checked!"; private static final string str_unchecked = " has unchecked!"; private int parentclickstatus=-1; private int childclickstatus=-1; private arraylist<parent> parents; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); resources res = this.getresources(); drawable devider = res.getdrawable(r.drawable.line); intent intent = getintent(); ip_address = intent.getstringextra("ip_address"); tableno = intent.getstringextra("tableno"); itmename = intent.getstringextra("button_text"); log.e("log_tag"," in ite list pages "); log.e("log_tag"," ip address : " +ip_address); log.e("log_tag", " table number : " +tableno); log.e("log_tag", " manu lict clicked : " +itmename); url= ip_address; // set expandablelistview values getexpandablelistview().setdivider(devider); getexpandablelistview().setchilddivider(devider); getexpandablelistview().setdividerheight(1); getexpandablelistview().setdescendantfocusability(viewgroup.focus_block_descendants); registerforcontextmenu(getexpandablelistview()); //creating static data in arraylist final arraylist<parent> dummylist = builddummydata(); // adding arraylist data expandablelistview values loadhosts(dummylist); } private arraylist<parent> builddummydata() { log.e("log_tag"," 1 "); // todo auto-generated method stub final arraylist<parent> list = new arraylist<parent>(); // creating arraylist of type parent class store parent class objects string result1= main_menu_list(); try { jsonarray jarray1 = new jsonarray(result1); log.e("log_tag", "json array length "+jarray1.length()); (int = 1; < jarray1.length(); i++) { //create parent class object final parent parent = new parent(); // json object parsing jsonobject json_data = jarray1.getjsonobject(i); string itemnamej = json_data.getstring("product_name"); string itempricej = json_data.getstring("price"); // set values in parent class object parent.setslno(i+"."); parent.setitemname(itemnamej); parent.setprice(itempricej ); parent.setchildren(new arraylist<child>()); // create child class object final child child = new child(); child.setprice(itempricej); child.setqut("1"); //add child class object parent class object parent.getchildren().add(child); //adding parent class object arraylist list.add(parent); } } catch(jsonexception e) { log.e("log_tag", "error parsing data "+e.tostring()); } return list; } private string main_menu_list() { log.e("log_tag"," 2 "); // todo auto-generated method stub string result1 = null; url= url + "rms/sub_manu.php"; arraylist<namevaluepair> postparameters= new arraylist<namevaluepair>(); postparameters.add(new basicnamevaluepair("itmename",itmename)); try { string response1 = customhttpclient.executehttppost(url,postparameters); result1 = response1.tostring(); } catch (exception e) { log.e("log_tag","error in http connection!!" + e.tostring()); } return result1; } private void loadhosts(arraylist<parent> newparents) { // todo auto-generated method stub log.e("log_tag"," 3 "); if (newparents == null) return; parents = newparents; // check expandablelistadapter object if (this.getexpandablelistadapter() == null) { //create expandablelistadapter object final myexpandablelistadapter madapter = new myexpandablelistadapter(); // set adapter expandablelist adapter this.setlistadapter(madapter); } else { // refresh expandablelistview data ((myexpandablelistadapter)getexpandablelistadapter()).notifydatasetchanged(); } } static class viewholder { textview slno ; textview itemname ; textview price; imageview rupees; imageview plu ; } /** * custom adapter create parent view (used grouprow.xml) , child view((used childrow.xml). */ private class myexpandablelistadapter extends baseexpandablelistadapter { private hashmap<integer, view> childmap = null; private int count = 1; private parent parent = null; private layoutinflater inflater; private viewholder holder = null; private int mpreviousselectedbtnid = -1; private int mselectedindex = -1; public myexpandablelistadapter() { // create layout inflator inflater = layoutinflater.from(itemlist.this); childmap = new hashmap<integer, view>(); } // function used inflate parent rows view @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parentview) { //int i=0; parent = parents.get(groupposition); if(convertview == null) { holder = new viewholder(); convertview = inflater.inflate(r.layout.grouprow, parentview,false); holder.itemname = (textview)convertview.findviewbyid(r.id.itemname); // title holder.price = (textview)convertview.findviewbyid(r.id.price); // description holder.slno = (textview)convertview.findviewbyid(r.id.slno); // description holder.rupees=(imageview)convertview.findviewbyid(r.id.rupees); // thumb image holder.plu = (imageview) convertview.findviewbyid(r.id.plu); convertview.settag(holder); } else { holder = (viewholder)convertview.gettag(); } convertview.setid(groupposition); holder.plu.setid(groupposition); holder.itemname.settag(item_name); holder.price.settag(item_price); if(parent != null) { holder.itemname.settext(parent.getitemname()); holder.price.settext(parent.getprice()); holder.slno.settext(groupposition+"."); } holder.plu.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { toast.maketext(itemlist.this,"plus button clicked!", toast.length_short).show(); mselectedindex = arg0.getid(); if(mpreviousselectedbtnid == arg0.getid()) { count++; } else { count = 2; mpreviousselectedbtnid = arg0.getid(); } log.d("elist", arg0.getid()+" >>>. button clicked "+count); log.d("elist", arg0.getid()+" >>>. button parent "+(view)arg0.getparent()); getexpandablelistview().expandgroup(arg0.getid()); view childview = getexpandablelistadapter().getchildview(arg0.getid(), 0, true, getexpandablelistview().getchildat(arg0.getid()), getexpandablelistview()); if(childview != null) { log.d("hash code", "in button click "+childview.hashcode()+""); textview qty = (textview) childview.findviewbyid(r.id.qut); //************************************************ // here try parent price value //remark :- 1st prent it's show current value when click anothere textview topic = (textview) findviewbyid(r.id.price); string totalprice = topic.gettext().tostring(); //****************************************************** log.e("log_tag","total price : " +totalprice); log.e("log_tag","total quaintity : " +qty.gettext().tostring()); log.e("log_tag","total price value : " +topic.gettext().tostring()); string val = qty.gettext().tostring(); if(qty != null) { //***************************************************** //here calculating price quantity qty.settext(count+" "); in = integer.valueof(topic.gettext().tostring()); totalqut = integer.valueof(val); system.out.println("total price after conv int :" + totalqut); totalv= in*totalqut; system.out.println("after value : "+ totalv); strvalp = string.valueof(totalv); //*********************************************** log.d("elist", "text view changes called "+ qty.gettag(r.id.qut)); qty.invalidate(); } else { log.d("elist", "text view null"); } ((myexpandablelistadapter)getexpandablelistadapter()).notifydatasetchanged(); } else { log.d("elist", "chilgdview view null"); } }}); return convertview; } // function used inflate child rows view @override public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parentview) { final parent parent = parents.get(groupposition); final child child = parent.getchildren().get(childposition); // inflate childrow.xml file child rows convertview = inflater.inflate(r.layout.childrow, parentview, false); // childrow.xml file elements , set values ((textview) convertview.findviewbyid(r.id.totalprice)).settext(child.getprice()); textview mqtytext = (textview) convertview.findviewbyid(r.id.qut); textview s2 = (textview) convertview.findviewbyid(r.id.totalprice); if(mqtytext!= null) { if(mselectedindex == groupposition) { mqtytext.settext(count+""); //******************************* //setting total price values s2.settext(strvalp); //******************************* } else { mqtytext.settext("1"); } mqtytext.settag(r.id.qut,"textview "+groupposition); } final textview sl = (textview) convertview.findviewbyid(r.id.totalprice); final textview qut = (textview) convertview.findviewbyid(r.id.qut); imageview image=(imageview)convertview.findviewbyid(r.id.mins); log.d("hash code", convertview.hashcode()+""); final textview sll = (textview) findviewbyid(r.id.price); int sllint = integer.valueof(qut.gettext().tostring()); image.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { toast.maketext(itemlist.this," mins button clicked!", toast.length_short).show(); string quantityval = qut.gettext().tostring(); string quantityval2 = sll.gettext().tostring(); string totalprice = sl.gettext().tostring(); log.i("log_tag value of quantity ",quantityval); log.i("log_tag value of totalprice ",totalprice); log.i("log_tag value of quantity ",quantityval2); int in = integer.valueof(sll.gettext().tostring()); int in2 = integer.valueof(sl.gettext().tostring()); if ((in2 != 0) && (count != 0)) { // *************************************** // here modify value when clicked minus button system.out.println("befor value : "+in); //in -=in; int val = in2 - in; system.out.println("after value : "+in); sl.settext(string.valueof(val)); count--; //****************************************** //string str = (string.valueof(in)); qut.settext(count+""); if(in == 0) { log.i("log_ tag ","if quantit queal 0"); sl.settext("0"); qut.settext("0"); } } } }); return convertview; } @override public object getchild(int groupposition, int childposition) { return getexpandablelistview().getchildat(groupposition); } //call when child row clicked @override public long getchildid(int groupposition, int childposition) { /****** when child row clicked function call *******/ if( childclickstatus!=childposition) { childclickstatus = childposition; toast.maketext(getapplicationcontext(), "$$$parent :"+groupposition + "**** child :"+childposition , toast.length_long).show(); } return childposition; } @override public int getchildrencount(int groupposition) { int size=0; log.e("log_tag"," 9 "); if(parents.get(groupposition).getchildren()!=null) size = parents.get(groupposition).getchildren().size(); return size; } @override public object getgroup(int groupposition) { log.i("parent", groupposition+"= getgroup "); return parents.get(groupposition); } @override public int getgroupcount() { return parents.size(); } //call when parent row clicked @override public long getgroupid(int groupposition) { log.i("parent", groupposition+"= getgroupid "+parentclickstatus); if(groupposition==2 && parentclickstatus!=groupposition){ //alert user toast.maketext(getapplicationcontext(), "parent :"+groupposition , toast.length_long).show(); } parentclickstatus=groupposition; if(parentclickstatus==0) parentclickstatus=-1; return groupposition; } @override public void notifydatasetchanged() { log.e("log_tag"," 13 "); // refresh list rows super.notifydatasetchanged(); } @override public boolean isempty() { log.e("log_tag"," 14 "); return ((parents == null) || parents.isempty()); } @override public boolean ischildselectable(int groupposition, int childposition) { log.e("log_tag"," 15 "); return true; } @override public boolean hasstableids() { log.e("log_tag"," 16 "); return true; } @override public boolean areallitemsenabled() { log.e("log_tag"," 17 "); return true; } }
}
Comments
Post a Comment