Get the position of a spinner in Android

前端 未结 4 1315
醉梦人生
醉梦人生 2020-12-14 06:07

I\'m trying to get the position (number) of the spinner when selected to use it in another Activity that will display a different map each time depending on the item selecte

4条回答
  •  时光说笑
    2020-12-14 06:30

        final int[] positions=new int[2]; 
        Spinner sp=findViewByID(R.id.spinner);
    
        sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    
            @Override
            public void onItemSelected(AdapterView arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText( arg2....);
            }
    
            @Override
            public void onNothingSelected(AdapterView arg0) {
                // TODO Auto-generated method stub
    
            }
        });
    

提交回复
热议问题