标签:
安卓中的下拉框 Spinner可以通过xml string中配置
<string-array name="spingarr"> <item>支付宝</item> <item>微信</item> </string-array>
布局文件
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:entries="@array/spingarr" android:id="@+id/payMode" android:layout_weight="1"> </Spinner>
获取spinner选中的值
private Spinner payMode; private int payNum; private String strPay; payMode = (Spinner)findViewById(R.id.payMode); payMode.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { strPay = (String)payMode.getSelectedItem(); } }); if(strPay.equals("支付宝")){ payNum = 0; }else if (strPay.equals("微信")){ payNum = 1; }
payMode = (Spinner) findViewById(R.id.payMode); //数据 data_list = new ArrayList<String>(); data_list.add("微信"); data_list.add("支付宝"); //适配器 arr_adapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data_list); //设置样式 arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //加载适配器 spinner.setAdapter(arr_adapter);
标签:
原文地址:http://www.cnblogs.com/zephyr-1/p/5358401.html