我正在使用微调器操作Action bar。我按照本教程第18步here
进行了操作我想在微调框中获取所选项目。我想使用switch
case
语句获取所选值
如何在onOptionsItemSelected
方法中获取所选项目?
答案 0 :(得分:1)
我认为您必须使用onNavigationItemSelected
方法来确定从微调器中选择的项目:
/**
* Actionbar navigation item select listener
* */
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
SpinnerNavItem selectedItem = navSpinner.get(itemPosition);
}
答案 1 :(得分:0)
// Encontre laSiguienteSolución
private SpinnerAdapter adaptador;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.name_layout);
spinnerFaena = getActionBar();
spinnerFaena.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
//Tengo Una Lista de Faenas que se Obtiene mediante WebService
final List<String> faenas = listaFaenas();
try {
adaptador = new ArrayAdapter<String>(
name_layout.this,
android.R.layout.simple_spinner_dropdown_item,
faenas);
}
//En el metodo que captura el Listener
@Override
public boolean onNavigationItemSelected(int index, long arg1) {
// TODO Auto-generated method stub
Toast.makeText(name_layout.this, "Estamos en " + adaptador.getItem(index).toString(),
Toast.LENGTH_SHORT).show();
return false;
}