android - Spinner selected Item Issue -


i have made 2 fragment. payment fragment , other add payment fragment. payment fragment contains shop spinner in witch multiple shops user select shop history of payment show if add payment button click add fragment screen show add payment , submit payment after submit payment screen fragment list. problem after fragment list screen selected shopspinner value change show first spinner value not show user selected spinner. paymentfragemt

public class paymentfragment extends fragment {     view myview;     arraylist<hashmap<string, string>> getshop;     string shopid;     fragment fragment;     int totalpayment,shopordertotalpayment;     arraylist<hashmap<string, string>> getpaypent;     listpaymenthistoryadapter listpaymenthistoryadapter;     spinner spinnershop;     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         myview = inflater.inflate(r.layout.payment_listview, container, false);         final context context = myview.getcontext();         final databasehelper mydbhelper = databasehelper.getinstance(context);         spinnershop = (spinner) myview.findviewbyid(r.id.searhshop);         final textview totalpaymenttextview=(textview) myview.findviewbyid(r.id.totalpayment);         final textview totalorderpaymenttextview=(textview) myview.findviewbyid(r.id.totalorderpayment);         final textview leftpaymenttextview=(textview) myview.findviewbyid(r.id.leftpayment);         final listview lvpayment=(listview)myview.findviewbyid(r.id.payment_listview);         getshop=javahelper.setshopspinner(spinnershop,myview);         spinnershop.setonitemselectedlistener(new adapterview.onitemselectedlistener() {             @override             public void onitemselected(adapterview<?> parent, view view, int position, long id) {                 shopid= getshop.get(position).get(shop.getcolid());                 /*get total payment*/                 totalpayment= javahelper.shoptotapayment(integer.parseint(shopid),context);                /* shop order payment*/                 shopordertotalpayment=javahelper.shopordertotapayment(integer.parseint(shopid),context);                 /*set left payment*/                 leftpaymenttextview.settext(integer.tostring(shopordertotalpayment-totalpayment));                 totalpaymenttextview.settext(integer.tostring(totalpayment));                 totalorderpaymenttextview.settext(integer.tostring(shopordertotalpayment));                 /* show payment list history*/                 string[] projectionpayment = {                         payment.getcolpayment(),                         payment.getcolcreated_at()                 };                 string wherclause=payment.getcolshopid()+"="+shopid;                 getpaypent= mydbhelper.thread_safe_select(payment.gettablname(),projectionpayment,wherclause,null,null,null);                 if (getpaypent!=null){                     listpaymenthistoryadapter=new listpaymenthistoryadapter(myview.getcontext(), getpaypent);                     lvpayment.setadapter(listpaymenthistoryadapter);                 }             }             @override             public void onnothingselected(adapterview<?> parent) {                 toast.maketext(context,"notselectclick",toast.length_short).show();             }         });         ((button) myview.findviewbyid(r.id.paymentadd)).setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {             bundle bundle=new bundle();             bundle.putint("shop_id",integer.parseint(shopid));             fragment=new addpayment();             fragment.setarguments(bundle);             fragmentmanager fragmentmanager=getfragmentmanager();             string title = "add payment";             if (fragment != null) {                 fragmentmanager.begintransaction().replace(r.id.content_frame,fragment).commit();             }             }         });         return myview;     } } 

add payment fragment

public class addpayment extends fragment {     view myview;     context context;     databasehelper mydbhelper;     fragment fragment = null;;     int colorid;     bundle bundle;     long leftpayment;     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         myview=inflater.inflate(r.layout.payment_add,container,false);         mydbhelper = databasehelper.getinstance(context);         context=myview.getcontext();         mydbhelper = databasehelper.getinstance(context);         final edittext addpaymentedittext=(edittext) myview.findviewbyid(r.id.paymentadd);         final textview leftpaymenttext=(textview) myview.findviewbyid(r.id.leftpayment) ;         bundle=getarguments();          if (bundle!=null){             final int shopid=bundle.getint("shop_id");             leftpayment=javahelper.shopordertotapayment(shopid,context)-javahelper.shoptotapayment(shopid,context);             leftpaymenttext.settext(long.tostring(leftpayment));             ((button) myview.findviewbyid(r.id.addpaymentbtn)).setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     string getpayment=addpaymentedittext.gettext().tostring();                     payment payment=new payment(getpayment,shopid,javahelper.getcurrenttimedate());                     if (mydbhelper.thread_safe_insert(payment.gettablname(),payment.getcontentvalues() ,context) != -1) {                         toast.maketext(context, "add success", toast.length_long).show();                     } else {                         toast.maketext(context, "some thing wrong", toast.length_long).show();                     }                     fragmentmanager fragmentmanager=getfragmentmanager();                     fragment=new paymentfragment();                     string title = "payment";                     javahelper.hidesoftkeyboard(getactivity());                     if (fragment != null) {                         fragmentmanager.begintransaction().replace(r.id.content_frame,fragment).commit();                     }                 }             });         }         addpaymentedittext.addtextchangedlistener(new textwatcher() {             @override             public void beforetextchanged(charsequence charsequence, int i, int i1, int i2) {                 log.v("beforetextchange","textchange event");             }              @override             public void ontextchanged(charsequence charsequence, int i, int i1, int i2) {                 log.v("ontextextchange","textchange event");             }              @override             public void aftertextchanged(editable editable) {                 if (!(editable.length()<=0)){                     long enterpayment=long.parselong(editable.tostring());                     leftpaymenttext.settext(long.tostring(leftpayment-enterpayment));                 }                 else {                     int length=editable.length();                     log.v("length",integer.tostring(length));                 }             }         });         return myview;     } } 


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -