Android adds data for the spinner

Source: Internet
Author: User

In Android, the spinner is the drop-down box. When you click it, the selection list is displayed, from which you can select data. The data in the spinner must come from the adapter. Therefore, when adding data to it, you must first define the template, that is, the XML file in layout.

<? XML version = "1.0" encoding = "UTF-8"?>
<Textview
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Id = "@ + ID/tvcateitem"
Android: textsize = "14px"
Android: textcolor = "@ color/Black"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
</Textview>

Here we define only the display, using the textview control.

Then in the Code:

String [] Cates = new string [] {"Unclassified", "Learning"}; arrayadapter adapter = new arrayadapter (getapplicationcontext (), R. layout. spinner_cate_item, Cates); spcate. setadapter (adapter );

Run:

Related Article

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.