In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "Android drop-down list box Spinner how to use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Android drop-down list box Spinner how to use" it!
The file directory is as follows:
Lay out a drop-down list box Spinner in activity_main.xml
Next, create the spinner_item.xml file under the layout folder, placing the controls in the drop-down list box, where only the text is displayed, so the code is as follows:
Then the call is made in MainActivity.java to set the data
Package com.example.administrator.myapplication; import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.Spinner;import android.widget.Toast; public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main) / / get control Spinner spinner = (Spinner) findViewById (R.id.spinner); / / data to be added to the drop-down list box String [] array = new String [] {"Tang Monk", "Sun WuKong", "Zhu Bajie", "Sha Wujing", "Little White Dragon"} / / create adapter final ArrayAdapter dataAdapter = new ArrayAdapter (MainActivity.this, R.layout.spinner_item, array); dataAdapter.setDropDownViewResource (R.layout.spinner_item); / / set adapter spinner.setAdapter (dataAdapter) for drop-down list box / / listening event spinner.setOnItemSelectedListener (new AdapterView.OnItemSelectedListener () {@ Override public void onItemSelected (AdapterView parent, View view, int position, long id) {String value = dataAdapter.getItem (position). ToString () / / get the value Toast.makeText of the selected drop-down list box item (MainActivity.this, "you selected:" + value, Toast.LENGTH_SHORT). Show ();} @ Override public void onNothingSelected (AdapterView parent) {/ / No selected processing events}});}}
The spinner completed for initializing the data is as follows:
The spinner of a selected item is as follows:
Thank you for your reading, the above is the "Android drop-down list box Spinner how to use" the content, after the study of this article, I believe you on the Android drop-down list box Spinner how to use this problem has a deeper understanding, the specific use also 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.