-
-
Save codeforfun-jp/d2fcb08d3cdc46bc7711d7b3188063fa to your computer and use it in GitHub Desktop.
How to use spinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Spinner spinner = findViewById(R.id.spinner); | |
spinner.setOnItemSelectedListener(this); | |
} | |
// 項目が選択された場合 | |
@Override | |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
Toast.makeText(this, parent.getSelectedItem() + "が選択されました", Toast.LENGTH_SHORT).show(); | |
} | |
// 項目が選択されなかった場合 | |
@Override | |
public void onNothingSelected(AdapterView<?> parent) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment