如何获得Spinner价值?

在Android中,我试图通过侦听器获取选定的Spinner值。

获得微调机价值的最佳方法是什么?


慕勒3428872
浏览 333回答 3
3回答

潇湘沐

Spinner mySpinner = (Spinner) findViewById(R.id.your_spinner);String text = mySpinner.getSelectedItem().toString();

开满天机

选择某些内容后,微调器应触发“ OnItemSelected”事件:spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {&nbsp; &nbsp; public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {&nbsp; &nbsp; &nbsp; &nbsp; Object item = parent.getItemAtPosition(pos);&nbsp; &nbsp; }&nbsp; &nbsp; public void onNothingSelected(AdapterView<?> parent) {&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android