Use spinner and setdropdownviewresource

Source: Internet
Author: User

Use spinner and setdropdownviewresource

Exercise 2: jointly use the spinner and setdropdownviewresource

Setdropdownviewresource of the adapter allows you to set the display mode of the drop-down menu, define the XML in the Res/layout directory, and set textview in the drop-down menu, for exampleProgramIn "R. layout. myspinner_dropdown" is the custom drop-down menu textview style. In addition to changing the drop-down menu style, you also made some dynamic effects on the spinner. When you click the spinner, after shaking the spinner, the drop-down menu (myanimation) will appear again ).

Step 2: Write the layout file main. xml and insert a button and a textview on the interface;

Step 2: Write color. XML to set the UI color;

Step 2: Create an anim folder under the res directory to store the animation effect and create a new my_anim.xml file;

Step 2: Create a New myspinner_dropdown.xml file in the layout folder under the res directory to store the layout of the pop-up content in the drop-down menu;

Step 2: Compile the event processing file Lianhe. java. The specific implementation process is as follows:

(1) define a drop-down menu to get the object with findviewbyid.

(2) define a string array and an arrayadepter to display the country to be selected.

(3) set a style for the drop-down menu.

(4) set the content adapter for the drop-down menu.

(5) add an animation to the drop-down menu.

Main Implementation of file Lianhe. JavaCodeAs follows:

 

 

 

 

The effect after the program is executed is 6-4. When you click the drop-down list box, a floating option box is displayed. You can select a country option, as shown in Figure 6-5.

 

 

 

 

 

This article is from the book Android .

Book details: http://blog.csdn.net/broadview2006/article/details/7104054

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.