Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created December 16, 2023 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/93b9826743062e4fb7b0803e1e99c639 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/93b9826743062e4fb7b0803e1e99c639 to your computer and use it in GitHub Desktop.
How to use spinner
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// リスト項目を作成する
String[] list = new String[5];
for (int i=0; i < 5; i++) {
list[i] = "項目" + (i+1) ;
}
// リスト項目をセットする
Spinner spinner = findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
list
);
spinner.setAdapter(adapter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment