Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Spinner in Android

Shulou Source: shulou.com Published: 2022-05-31 22:50:58 09月25日 Update

This article is a detailed introduction to "how to use Spinner in Android". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to use Spinner in Android" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

● Adapter settings, call setAdapter() method.

● Add Item selection time processing, call setOnItemSelectedListener() method, and pass AdapterView.OnItemSelectedListener instance as parameter.

Android Spinner routines source code (Java)

ArrayAdapter

< String>

adapter = new ArrayAdapter

< String>

( this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item); adapter.add("red"); adapter.add("green"); adapter.add("blue"); Spinner spinner = (Spinner) findViewById(id.spinner); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected( AdapterView

< ?>

parent, View view, int position, long id) { Spinner spinner = (Spinner) parent; Log.v("Test", "id = " + id + "(" + spinner.getSelectedItem().toString() + ")"); } @Override public void onNothingSelected(AdapterView

< ?>

parent) { } });

Android Spinner routines source code (Resource)

< Spinner android:id="@+id/spinner" android:layout_height="wrap_content" android:layout_width="fill_parent"/>

Read here, this article "How to use Spinner in Android" has been introduced, want to master the knowledge points of this article also need to practice to understand, if you want to know more related content of the article, welcome to pay attention to the industry information channel.

Tags: Articles content methods source code processing proper parameters examples ideas new knowledge time more steps knowledge knowledge points articles details industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info vpn OPPO Reno Xiaomi