@Override public boolean onOptionsItemSelected(MenuItem item){ //change the spinners item depending on menu choice switch(item.getItemId()){ case R.id.lengthMenu: adapter = ArrayAdapter.createFromResource(this, R.array.lengthArray, android.R.layout.simple_spinner_item); adapter.notifyDataSetChanged(); return true; case R.id.weightMenu: adapter = ArrayAdapter.createFromResource(this, R.array.weigthArray, android.R.layout.simple_spinner_item); adapter.notifyDataSetChanged(); return true; case R.id.liquidsMenu: adapter = ArrayAdapter.createFromResource(this, R.array.liquidsArray, android.R.layout.simple_spinner_item); adapter.notifyDataSetChanged(); return true; default: return true; }
ArrayAdapter<CharSequence> adapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); answer = (TextView) findViewById(R.id.answer); unitSize = (EditText) findViewById(R.id.unitSize); adapter = ArrayAdapter.createFromResource(this, R.array.lengthArray, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); firstUnit = (Spinner) findViewById(R.id.firstUnit); secondUnit = (Spinner) findViewById(R.id.secondUnit); firstUnit.setOnItemSelectedListener(this); secondUnit.setOnItemSelectedListener(this); firstUnit.setAdapter(adapter); secondUnit.setAdapter(adapter); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)