安卓学习第16课——Spinner

今天学习一下Spinner

<LinearLayout 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"
    android:orientation="vertical" >
<Spinner
     android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:entries="@array/books"
    android:prompt="@string/tip"
    />
    <Spinner
        android:id="@+id/spinner"
     android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:prompt="@string/tip"
    />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="books">
        <item>java</item>
        <item>android</item>
        <item>web</item>
    </string-array>
</resources>
package com.example.spinner;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class MainActivity extends Activity {

    Spinner spinner;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinner=(Spinner) findViewById(R.id.spinner);
        String[] arr={"孙悟空","猪八戒","唐僧"};
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_multiple_choice, arr);
        spinner.setAdapter(adapter);
    }
}
时间: 2024-08-28 17:36:20

安卓学习第16课——Spinner的相关文章

安卓学习第13课——BaseAdapter

BaseAdapter创建这么一个对象,需要些四个方法. int getCount(); Object getItem(int position); long getItemId(int position);View getView(int position, View convertView, ViewGroup parent);(1)列表中的项数(2)返回值的列表内容(3)获得postion处的列表项的ID(4)该列表项里的组件 package com.example.baseadapter

安卓学习第12课——SimpleAdapter

SimpleAdapter一点也不简单,他的参数就带了5个,天哪,晕了.. 今天学的这个适配器, public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) 看这个大概明白,参数分别是第一个:表示访问整个android应用程序接口,基本上所有的组件都需要,一般都写this(改天研究一下),第二个应该是这个List对象

安卓学习第9课——计时器chronometer

今天学习了钟表及计时器.. 我觉得AnalogClock和DigitalClock直接使用就可以.唯一需要知道的就是AnalogClock是可以修改表盘和分针时针的. 方法是android:dail及android:hand_minute和hand_hour. 下面介绍的是计时器的用法. 首先xml中只要放入一个chronometer和一个按钮即可.为的是是点击启动按钮,开始计时,20s停止. package com.example.chronometer; import android.app

安卓学习第11课——AutoCompleteTextView

...在百度上搜了这么一段.理解了ArrayAdapter的三个参数的用途 1. 这个小例子是要显示一个数组,我们就用ArrayAdapter,数组适配器,数据的数据类型<>是String类型的,数据的数据类型还可以是其他的包括对象类型的 2. ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(ArrayListDemo.this, android.R.layout.simple_list_item

安卓学习第10课——listview

1.普通listview <LinearLayout 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" androi

安卓学习第8课——开关ToggleButton、Switch

今天学的是对开关的监听,两种开关ToggleButton和switch <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="ma

安卓学习第三课——常见布局

1.相对布局 简单的说,就是通过描述每个组件所在的位置,使用的layout_below等,就是控制组件与组件之间的位置关系. 2.绝对布局 就是通过描述他的x,y坐标来确定位置 3.线性布局 有两种是水平和竖直对其方式,一般情况下整体会使用线性布局,来排列众多的组件 3.帧布局 我感觉就是一层一层的,默认的情况下,多个组件是在同一个位置,所以你需要去修改位置.同时可以选择是否显示. 这可以用来描述视频播放器暂停键的控制方法. 代码如下. <?xml version="1.0" e

安卓学习第7课——checkbutton

1.布局 <TableLayout 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" android:orienta

安卓学习第6课——button

今天学会了按钮的背景图片是可以改变的... 背景可以不是图片,而是一个xml文件. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="带文字的图片按钮" android:background="@drawable/button_selector" android:textSize=&