java - Passing data from spinner to TextView depending on user selection -


so have spinner contains 2 possible options. have 1 textview in other activity user selection show.

the problem is, how set in second activity? tried numerous times various if - statements, nothing worked.

here's code of spinner

public void onitemselected(adapterview<?> parent, view view, int position, long id) {                         if (position == 0){                              intent.putextra("ciljjepovecanjetezine", cilj.getselecteditem().tostring());                          } else if (position == 1){                             intent.putextra("ciljjemrsavljenje", cilj.getselecteditem().tostring());                          }                     }                      @override                     public void onnothingselected(adapterview<?> parent) {                      }                 }); 

and here's second activity in want text appear

string prehrana = intent.getstringextra("ciljjepovecanjetezine");         string prehrana2 = intent.getstringextra("ciljjemrsavljenje");          ciljprehranarezultat = (textview) findviewbyid(r.id.textviewprehranaciljrezultat);          ciljprehranarezultat.settext(prehrana);         ciljprehranarezultat.settext(prehrana2); 

now how set if user selects option one, option 1 shows in textview , if user selects option two, option 2 appears?

thanks!!

you should use global string variable save spinner value , send other activity on press of button (or whatever using change activity). example:

string spinnervalue;  public void oncreate(...){ ... spinnervalue = cilj.getselecteditem().tostring() ... }  public void onitemselected(...){      spinnervalue = cilj.getselecteditem().tostring(); }   intent intent = new intent(this_activity,other_activity.class); intent.putextra("spinnervalue",spinnervalue); startactivity... 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -