How to realize the effect of drop-down list by Android Studio
This article mainly explains "Android Studio how to achieve the drop-down list effect", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Android Studio how to achieve the drop-down list effect" bar!
Title
Use ArrayAdapter to implement a city's drop-down list.
Answer
Activity_main.xml:
City.xml:
Beijing, Shanghai, Wuhan, Nanjing, Nanchang, Shenzhen, Changsha, Guangzhou, Kunming, Guiyang, Harbin, Suzhou, Hangzhou, Nanyang Shijiazhuang, Jinan, Yinchuan, Hohhot, Xi'an Hefei, Zhengzhou, Qingdao, Taipei, Lanzhou, Taiyuan, Urumqi, Haikou, Shenyang, Fuzhou, Nanning, Chengdu, Changchun, Lhasa Xining
MainActivity.java:
Package com.example.myapplication;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.Spinner;public class MainActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Spinner spinner= (Spinner) findViewById (R.id.spinner1); / / initialize the control String [] city=getResources () .getStringArray (R.array.spinnername) / / create the data source ArrayAdapteradapter= new ArrayAdapter (this,android.R.layout.simple_spinner_item,city); / / create the Adapter and bind the data source / / the first parameter indicates which Activity is displayed, the second parameter is the style of the system drop-down box, and the third parameter is the array. Spinner.setAdapter (adapter); / / bind Adapter to the control}}
Running result
Thank you for reading, the above is the content of "how to achieve the drop-down list effect of Android Studio". After the study of this article, I believe you have a deeper understanding of how to achieve the drop-down list effect of Android Studio, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!