"go" Android: Control spinner Implementation Drop-down list

Source: Internet
Author: User
<span id="Label3"></p><p><p>Original Url: http://www.cnblogs.com/tinyphp/p/3858920.html</p></p><p><p>In Web development, HTML provides a drop-down list implementation that uses the <select> element to implement a drop-down list in which each Drop-down list item uses the <option> Representation. This is an essential interactive component in Web development, and the corresponding implementation in Android is Spinner.</p></p><p><p><strong>Method One:</strong></p></p><p><p>Static display of Spinner options in Resource mode:</p></p><pre><pre><spinner android:layout_width= "match_parent" android:layout_height= "wrap_content" android:id= "@ +id/spinner2 " android:entries=" @array/spingarr " /></pre></pre><p><p>Data files:</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><pre><?xml version= "1.0" encoding= "utf-8"?><resources> <string-array name= "spingarr" > < Item> Beijing </item> <item> Shanghai </item> <item> Guangzhou </item> <item> Shenzhen </item> </string-array></resources></pre></pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p></p></p><p><p><strong>Usage 2:</strong></p></p><p><p>Dynamically display the Spinner option in code mode to add data to Spinner with the adapter</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre>Package Com.example.testspanner;import Java.util.arraylist;import Java.util.list;import android.app.Activity; Import Android.os.bundle;import Android.widget.arrayadapter;import Android.widget.spinner;public class MainActivity Extends Activity {private Spinner spinner;private list<string> data_list;private arrayadapter<string> arr_ Adapter @Override protected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.spinner); Spinner = (spinner) Findviewbyid (r.id.spinner); Data data_list = new arraylist<string> (); Data_list.add ("beijing"); Data_list.add ("shanghai"); Data_list.add ("guangzhou"); Data_list.add ("shenzhen"); Adapter arr_adapter= new Arrayadapter<string> (this, android. r.layout.simple_spinner_item, data_list); Set Style Arr_adapter.setdropdownviewresource (android. r.layout.simple_spinner_dropdown_item); Load Adapter Spinner. Setadapter (arr_adapter); }}</pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p>Layout file Added:</p></p><pre><pre><spinner android:layout_width= "match_parent" android:layout_height= "wrap_content" android:id= "@ +id/spinner " /></pre></pre><p><p>"go" Android: Control spinner Implementation Drop-down list</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.