public class MainActivity extends Activity {//声明spinner对象private Spinner spinner;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//根据id获取对象spinner = (Spinner) findViewById(R.id.spinner1);//显示的数据final String arr[]=new String[]{"星期一","星期二","星期三","星期四","星期五","星期六","星期日"};//adpater对象//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arr);//List<? extends Map<String, ?>> List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();Map<String, Object> map = new HashMap<String, Object>();map.put("logo", R.drawable.ic_launcher);map.put("text", "xxxx说明操作");Map<String, Object> map2 = new HashMap<String, Object>();map2.put("logo", R.drawable.ic_launcher);map2.put("text", "xxx说明xxx");data.add(map);data.add(map2);SimpleAdapter simpleAdapter = new SimpleAdapter(this, data, R.layout.activity_item, new String[]{"logo","text"}, new int[]{R.id.imageView1,R.id.textView1});//设置显示的数据//spinner.setAdapter(arrayAdapter);spinner.setAdapter(simpleAdapter);Toast.makeText(getApplicationContext(), "main Thread"+spinner.getItemAtPosition(spinner.getSelectedItemPosition()), Toast.LENGTH_LONG).show();//注册事件spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {@Overridepublic void onItemSelected(AdapterView<?> parent, View view,int position, long id) {Spinner spinner = (Spinner) parent;Toast.makeText(getApplicationContext(), "xxxx"+spinner.getItemAtPosition(position), Toast.LENGTH_LONG).show();}@Overridepublic void onNothingSelected(AdapterView<?> parent) {Toast.makeText(getApplicationContext(), "没有改变的处理", Toast.LENGTH_LONG).show();}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}


更多相关文章

  1. android异步取数据
  2. Android数据存储路径位置
  3. android中Json数据保存方式
  4. [置顶] Android加载数据过程中的菊花显示
  5. android webview 中网页数据与js交互
  6. Android 解决 RecyclerView 嵌套 ScrollView 数据显示不全的问题
  7. 通过CMD 查看android APP数据库表
  8. android 利用socket 发送Json数据demo
  9. Android 简单数据库(增删改查)

随机推荐

  1. xamarin Android activity生命周期详解
  2. Android - 主要的UI元素
  3. [C#] 與Android共舞–手機post資料給Serv
  4. Android中巧妙的位运算
  5. EventBus粘性事件
  6. Android(安卓)GPS 定位的实现(2-1) 使用Goo
  7. Android--高级组件
  8. android随机生成验证码
  9. Android Studio SDK版本兼容问题,拷贝的A
  10. Android多核与单核的性能持平的问题