Android - How to get the selected item value from a spinner and put it into a string? -
I have read many questions on this thread, but none of them help me ... this is my code Is: I imc_met to Where is the problem? Thx in advance After . imc_met = Spinner.getSelectedItem () toString (); Instead of: imc_met = parent.getItemAtPosition (POS) .toString (); updated: It takes you not telling listeners to spin correctly, a function like below: @ override protected void build (bundle saved instainstate) {super. Connet (Saved Instantstate); SetContentView (R.layout.activity_main); Spinner Spinner = (Spinner) Find VViBiID (RID.imc-spinner); // string array and a default spinner layout ArrayAdapter & lt; Charsequence & gt; Create an array adapter using Adapter = Arrayadaptor.Creatofrom Resource (This, R. Ram.ImcAir, AndroidR.Let.Simple_spinner_item); // Specify the layout to use when adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item) appears on the list; // Adapter spinner spinner. Apply to the adapter; } Selected items on public zeros (adapterview & lt;? & Gt; parent, view view, integer, long id). You can retrieve the selected items using imc_met = parent.getItemAtPosition (pos) .toString (); }
public string imc_met; I declare as . The problem is that imc_met does not include the value of the spin of selected items, but it is null ...
spin.setOnItemSelectedListener (new OnItemSelectedListener () {@Override public void onItemSelected (AdapterView & LT ;? & gt; arg0, see ARGl, integer aRG2, long arg3) {string imc_met = spin.getSelectedItem ( ) toString () ;.} @Override public void onNothingSelected (AdapterView & LT ;? & gt; arg0) {/ / TODO auto-generated method stub}});
Comments
Post a Comment