Android list selection box spinner details and examples

Android list selection box spinner details and examples

Spinner is a list selection box for Android, but spinner does not need to display a drop-down list, but is equivalent to a pop-up menu for users to choose.

Spinner properties:

● Android: spinnermode: list display mode. There are two options: dialog and dropdown. If it is not specially set, it is a drop-down list. ● Android: entries: use < string array... / > resources to configure data sources. ● Android: prompt: sets the title for the current drop-down list, which is only valid in dialog mode. To pass a "@ string / name" resource, you need to define < string... / > in the resource file.

Spinner common events:

● adapterview.onitemclicklistener: triggered when a list item is clicked. ● adapterview.onitemlongclicklistener: the list item is triggered on time. ● adapterview.onitemselectedlistener: triggered when a list item is selected.

Spinner data binding:

● using XML to set array resources is simple and convenient, but not flexible. If only fixed simple data is displayed, it can be used. ● use the adapter interface to set. The most common way is dynamic loading, which is flexible. You can set various styles and data sources.

XML file structure (generally written in string.xml file)

For simple data, you can use arrayadapter to set the adapter, but for slightly complex data, arrayadapter cannot meet the requirements. At this time, you need to use simpleadapter for adaptation.

The simpleadapter adapter is also based on the adapter, which can map static layout files in XML format to views. You can specify list < map < p, t > > format data. The data in list corresponds to each row in spinner, and the data in map corresponds to no data. Mspinner = (spinner) findviewbyid (r.id.sp_bank);

The spinner pop-up list event is listview, so various methods of listview can be used in the spinner pop-up window. At that time, you can also customize the data source. The custom adapter inherits baseadapter to achieve more flexible and complex effects.

The onitemselectedlistener event will be automatically called by spinner during initialization because the system will automatically load the default value.

Solution: manually add default values, where the main calling sequence is required and must be invoked before the registration method.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>