반응형





 ☞ 1. 액티비티.java

package com.android.sinnerDemo;


import android.app.Activity;

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.Spinner;


public class SinnerDemoActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        String [] numbers = {"NC 다이노스","롯데 자이언트","삼성 라이온스","두산 베어스"

        ,"한화 이글스","KIA 타이거즈","넥센 히어로즈","LG 트윈스","SK 와이번즈",};

        

        Spinner spiner = (Spinner) findViewById(R.id.spinner1);

        

        ArrayAdapter<String> adapter = new ArrayAdapter<String>

        (this, android.R.layout.simple_spinner_item, numbers);

        

        spiner.setAdapter(adapter);

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        

        spiner.setSelection(0);

        

    }

}

 ☞ main.xml <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >


    <Spinner

        android:id="@+id/spinner1"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        />


</LinearLayout>

반응형
반응형