Views_Spinner

old/API_Demo 2010. 5. 6. 15:42

[Spinner1.java]


public class Spinner1 extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.spinner_1);

        Spinner s1 = (Spinner) findViewById(R.id.spinner1);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.colors, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        s1.setAdapter(adapter);

        Spinner s2 = (Spinner) findViewById(R.id.spinner2);
        adapter = ArrayAdapter.createFromResource(this, R.array.planets,
                android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        s2.setAdapter(adapter);
    }
}


[spinner_1.xml]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/spinner_1_color"
    />

    <Spinner android:id="@+id/spinner1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/spinner_1_color_prompt"
    />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="@string/spinner_1_planet"
    />

    <Spinner android:id="@+id/spinner2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/spinner_1_planet_prompt"
    />

</LinearLayout>



[strings.xml]

    <string name="spinner_1_color">Color:</string>
    <string name="spinner_1_planet">Planet:</string>
    <string name="spinner_1_color_prompt">Choose a color</string>
    <string name="spinner_1_planet_prompt">Choose a planet</string>

'old > API_Demo' 카테고리의 다른 글

Views_Tabs_Content By Id  (0) 2010.05.06
VIews_SeekBar  (0) 2010.05.06
Views_ScrollBars_Fancy  (0) 2010.05.06
Views_ScrollBars_Fancy  (0) 2010.05.06
Views_ScrollBars_Basic  (0) 2010.05.06
Posted by jazzlife
,