demo06
2016-03-03 23:11
239 查看
city_data.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="city_labels"> <item>中国-北京</item> <item>中国-上海</item> <item>中国-长沙</item> </string-array> </resources> ============ string.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name" >demo06OnItemSelectedListener </string> <string name="action_settings" >Settings </string> <string name="hello_world" >Hello world! </string> <string name="city_list" >Hello world! </string> </resources> ============================ main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:id="@+id/info" android:text="@string/city_list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Spinner android:id="@+id/city" android:prompt="@string/city_list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:entries="@array/city_labels" /> </LinearLayout> ============================== package com.example.demo06onitemselectedlistener; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.Spinner; import android.widget.TextView; public class MainActivity extends Activity { private Spinner city= null; private TextView info = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.city=(Spinner)super.findViewById(R.id.city); this.info=(TextView)super.findViewById(R.id.info); this.city.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int idx, long id) { String value = adapterView.getItemAtPosition(idx).toString(); MainActivity.this.info.setText("you best like city is:"+value); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } @Override public 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; } }
相关文章推荐
- Leetcode上的各种“Reverse”
- 聚合搜索 Meta Search实践
- spring+mail+maven(spring 发送邮件)
- [leetcode268]Missing Number
- getRawX、getRawY和getX、getY的区别
- [运筹学]关于动态规划的2个问题-最长公共子序列与最长非降子序列问题
- SGU 223. Little Kings
- Objective-C对象之类对象和元类对象
- Emacs折腾02-安装
- 进程
- 基于XMPP协议的手机多方多端即时通讯方案
- Nginx配置Restful风格url
- Aidl与信使的区别
- java 加载dll介绍(转)
- 关于日志的那些事
- STL笔记(3)——空间配置器Allocator(一)
- Android中AIDL进程间通信
- 3 AMQP 0-9-1 Model Explained
- OpenCV3.0 决策树的使用
- 设置UIView四个角中任意角的圆角效果