android - in customize listview unable to fetch proper data -
here using activity in there list view,which populating form xml string,the population fine,in listview there 2 buttons
clicking on no increasing , decreasing.onsubmit buttons want datum modified 1 shown in submit.e.g 2 seaters selected 2.
the code snippts are:
my xml private static string seatxml="<?xml version=\"1.0\" encoding=\"utf-8\"?><seatlist>" +"<seatselection><seater>two</seater></seatselection>" +"<seatselection><seater>four</seater></seatselection>" +"<seatselection><seater>six</seater></seatselection>" +"<seatselection><seater>eight</seater></seatselection>" +"<seatselection><seater>ten</seater></seatselection>" +"</seatlist>";
here populating listview
private void populateseatlist() { // todo auto-generated method stub seatitems=new arraylist<hashmap<string,string>>(); xmlparser parser=new xmlparser(); document doc=parser.getdomelement(seatxml); nodelist nl=doc.getelementsbytagname(key_record); string seatname=""; (int = 0; < nl.getlength(); i++) { map=new hashmap<string, string>(); element e=(element)nl.item(i); // adding each child node hashmap key => value map.put(key_seat,parser.getvalue(e, key_seat)); //this fetch seater value 2 seater,3 seater map.put(key_seat_qty,""+qty); seatitems.add(map); } adapter=new seatadapter(this, seatitems); seatlistview.setadapter(adapter); // makeatoast(seatname); }
the getview function in adapter class
int i=0; @override public view getview(final int position, view convertview, viewgroup parent) { // todo auto-generated method stub view view=convertview; if(convertview==null) view=inflater.inflate(r.layout.seat_desc,null); textview seatname=(textview)view.findviewbyid(r.id.textview_seat_no); button buttonminus=(button)view.findviewbyid(r.id.button_minus); button buttonplus=(button)view.findviewbyid(r.id.button_plus); final textview seatinput=(textview)view.findviewbyid(r.id.textview_seat_input); seatinfo=new hashmap<string, string>(); seatinfo=data.get(position); seatname.settext(seatinfo.get(seatselectionactivity.key_seat)+" seater:"); seatinput.settext(""+i); // menuinfo.get(menuscreenactivity.key_menuname) buttonplus.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated stub i=integer.parseint(seatinput.gettext().tostring()); if(!(i>=10)) i++; seatinput.settext(""+i); // seatinfo.put(seatselectionactivity.key_seat, seatinfo.get(seatselectionactivity.key_seat)); seatinfo.put(seatselectionactivity.key_seat_qty,seatinput.gettext().tostring()); data.set(position, seatinfo); // notifydatasetchanged(); } }); buttonminus.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo ,goto-generated method stub i=integer.parseint(seatinput.gettext().tostring()); if(!(i<1)) i--; seatinput.settext(""+i); // seatinfo.put(seatselectionactivity.key_seat, seatinfo.get(seatselectionactivity.key_seat)); seatinfo.put(seatselectionactivity.key_seat_qty,seatinput.gettext().tostring()); data.set(position, seatinfo); // notifydatasetchanged(); } }); return view; }
i used code selected seats & worked
buttonplus.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated stub i=integer.parseint(seatinput.gettext().tostring()); if(!(i>=10)) i++; seatinput.settext(""+i); data.get(position).put(seatselectionactivity.key_seat_qty, seatinput.gettext().tostring()); } });
Comments
Post a Comment