Detailed explanation and example code of Android spinner and adapter mode

Recently, I made a project to use Android spinner. Here is a simple example to test how to use it.

Spinner

Is a drop-down list. Drag a spinner control into the Android interface, and set Android: entries = "@ array / spinner_data" in the property, where spinner_ Data is the array set in string. A fixed written value in an array. The drop-down list can be set in the interface.

Of course, for a good user experience, you can set the Android: spinnermode = "dialog" attribute to make the drop-down list have a pop-up box.

Adapter:

The adapter is mainly responsible for capturing data from the data source and transmitting it to various UI components. The main adapters are arrayadapter and baseadapter. That is, the adapter is responsible for obtaining data from a data source, such as an array, transmitting it to the spinner and displaying it on the interface.

First define the data source

Data source 2

Secondly, define a class myadapter inheritance and abstract class baseadapter. There are four abstract methods.

Then in the main function

First find the spinner control and instantiate a new adapter. Grab the data in the data source SS through the adapter.

The most important methods of the baseadapter are the getcount () and getview () methods. The former returns the length of the data source, and the latter performs some operations.

Of course, you can use a simpler arrayadaper adapter.

Through the above statements, you can directly locate in the array SS.

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
分享
二维码
< <上一篇
下一篇>>