ArrayAdapter 사용한 Spinner 예제

 

package co.kr.codein;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.view.ViewGroup;
import android.widget.Spinner;
import android.widget.ArrayAdapter;

public class SpinnerExam extends Activity
{
    private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
    private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;

    private String[] data = {"2004""2005""2006""2007"};

    @Override protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        setContentView(linearLayout);

        Spinner spinner  = new Spinner(this);
        linearLayout.addView(spinner, createParam(100, WC));

        ArrayAdapter<String> arrayAdapter
            = new ArrayAdapter<String>(this, R.layout.rowdata, data);

        spinner.setAdapter(arrayAdapter);
    }

    private LinearLayout.LayoutParams createParam(int w, int h){
        return new LinearLayout.LayoutParams(w, h);
    }
}

 

 
YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST