您的位置:首页 > 移动开发 > Android开发

通过资源文件配置Android下拉列表…

2013-12-30 20:36 323 查看




1、首先找到我们res文件夹下边的layout下边的xml文件

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 
 
xmlns:tools="http://schemas.android.com/tools"
 
  android:layout_width="match_parent"
 
 
android:layout_height="match_parent"
 
  tools:context=".MainActivity"
>

 
  <TextView
 
     
android:layout_width="wrap_content"
 
     
android:layout_height="wrap_content"
 
     
android:layout_marginTop="10px"
此部分的值在values文件夹当中string.xml
 
     
android:text="@string/city" />
 
 
<Spinner 
 
     
android:id="@+id/myspinner"
 
     
android:prompt="@string/city"
 
     
android:layout_width="fill_parent"
 
     
android:layout_height="wrap_content"
 
     
android:layout_marginTop="40px"
下边代表的是我们values文件夹当中的city.xml当中的数值
 
     
android:entries="@array/citylist"/>
</RelativeLayout>

2、找到我们values文件夹当中的string.xml

<?xml
version="1.0" encoding="utf-8"?>
<resources>
 
  <string
name="app_name">SpinnerDemo</string>
 
  <string
name="hello_world">Hello
world!</string>
 
  <string
name="menu_settings">Settings</string>
 
  <string
name="city">请选择您所在的城市</string>
</resources>

3、找到vaule文件夹下边的city.xml

<?xml
version="1.0" encoding="utf-8"?>
<resources>
 
  <string-array
name="citylist">
 
     
<item>北京</item>
 
     
<item>上海</item>
 
     
<item>南京</item>
 
     
<item>深圳</item>
 
 
</string-array>
</resources>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: