Spinner ComboBox DropDown set on selected item listener setOnItemSelectedListener Java Android example

Spinner, ArrayAdapter, setOnItemSelectedListener, onItemSelected, setDropDownViewResource

MainClass.java

public class Vypocet extends Activity {
 Spinner   hSpinnerMetry;
// .......
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
	       hSpinnerMetry = (Spinner) findViewById(R.id.idSpinnerMetry);
	        ArrayAdapter<CharSequence> adapterMetry = ArrayAdapter.createFromResource(
	        		this, R.array.metry_array, android.R.layout.simple_spinner_item);
	        adapterMetry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	        hSpinnerMetry.setAdapter(adapterMetry);
 
	           hSpinnerMetry.setOnItemSelectedListener(
	                    new OnItemSelectedListener() {
	                        public void onItemSelected(
	                                AdapterView<?> parent, View view, int position, long id) {
	                        int nPos = position;
	                        }
 
	                        public void onNothingSelected(AdapterView<?> parent) {
 
	                        }
	                    });	        
 
      }
}

strings.xml

 
<string-array name="metry_array">
<item>m</item>
<item>dm</item>
<item>cm</item>
<item>mm</item>
</string-array>
This entry was posted in Android Examples Code and tagged , , , , , , . Bookmark the permalink.


Comments are closed.



10,094 views