JS 与 trick 代码的运用及解析全攻略
1215
2022-10-24
Android下拉框
Android下拉框
Activity_main.xml
MainActivity.java
package pw.gutao.android_08_0628;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;import android.widget.MultiAutoCompleteTextView;import android.widget.Spinner;import android.widget.Toast;public class MainActivity extends AppCompatActivity { private AutoCompleteTextView autoCompleteTextView; private MultiAutoCompleteTextView multiAutoCompleteTextView; private Spinner spinner; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取下拉列表 spinner = (Spinner) findViewById(R.id.s_main_1); //定义数组,保存省份 final String[] provinces = {"湖南","湖北","河南","河北","山东","山西"}; //创建适配器 ArrayAdapter adapters = new ArrayAdapter(this,android.R.layout.simple_list_item_1,provinces); //设置适配器 spinner.setAdapter(adapters); //获取当前选中的选项 spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView> parent, View view, int position, long id) { Toast.makeText(MainActivity.this,provinces[position]+"省",Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView> parent) { } }); }}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~