SoFunction
Updated on 2025-04-09

Android list control Spinner simple usage example

This article describes the simple usage of Android list control Spinner. Share it for your reference, as follows:

Android's Spinner control is used to display list items, similar to a set of radio boxes RadioButton. Here is a brief introduction to its usage:

xml layout:

<?xml version="1.0" encoding="utf-8"?>
<LinaerLayout xmlns:andro
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
   >
<Spinner
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:entries="@strings/books"
    android:prompt="@string/tip"
    />
<Spinner
    android:
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/tip"
    />
</LinaerLayout>

Java code part:

package .test06;
import ;
import ;
import ;
import ;
import ;
import ;
public class MainActivity extends Activity {
   Spinner spinner;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    (savedInstanceState);
    setContentView(.activity_main);
    spinner=(Spinner)findViewById();
    String[] arr={"Sun Wukong","Zhu Bajie","Tang Monk"};
    ArrayAdapter&lt;String&gt; adapter=new ArrayAdapter&lt;String&gt;(this,.simple_list_item_multiple_choice,arr);
    (adapter);
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;
  }
}

For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.