In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.