java - Text box value not updating properly according to the change in spinner value (and i have tried most of the methods in stackoverflow) -


there spinner in mainactivity , 1 text box in fragment. task change value of text box according selected spinner value. code works well, textbox changes state after 2 swipes. don't know why lagging happening. me out (before downvoting kindly solutions)

here code in main activity

spinner = (spinner)findviewbyid(r.id.spinner2); final arrayadapter<string> dataadapter1 = new arrayadapter<>(this,android.r.layout.simple_spinner_item,array2); dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinner.setadapter(dataadapter1); spinner.invalidate();  spinner.setonitemselectedlistener(new adapterview.onitemselectedlistener() {     @override     public void onitemselected(adapterview<?> parent, view view, int position, long id) {         //dataadapter1.notifydatasetchanged();         toast.maketext(getapplicationcontext(),"well",toast.length_long).show();         string pos = (string) spinner.getselecteditem();         sharedpreferences sharedpref = getsharedpreferences("mode", activity.mode_private);         sharedpreferences.editor prefeditor = sharedpref.edit();         prefeditor.putstring("userchoicemode", pos);         prefeditor.commit();     }     @override     public void onnothingselected(adapterview<?> parent) {     } }); 

my fragment code :

final textview modeselect = (textview) view.findviewbyid(r.id.pass);  final sharedpreferences sharedpref = this.getactivity().getsharedpreferences("mode", activity.mode_private); string = sharedpref.getstring("userchoicemode",selected);  modeselect.settext("" + get); 

in fragment

 @override public void setuservisiblehint(boolean isvisibletouser) {     try {         if (isvisibletouser) {             final textview modeselect = (textview) view.findviewbyid(r.id.pass);  final sharedpreferences sharedpref = this.getactivity().getsharedpreferences("mode", activity.mode_private); string = sharedpref.getstring("userchoicemode",selected);  modeselect.settext("" + get);         }     } catch (exception e) {         e.printstacktrace();     }     super.setuservisiblehint(isvisibletouser); } 

just add override method fragment , put value of selected spinner item in text view of fragment in method. inflated view should declared globally


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -