Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- TOEIC
- 엑티비티
- 토익
- 브로드케스트 리시버
- 자바
- Looper
- 안드로이드
- Java
- 걸스데이
- rainbow
- xml
- 이클립스
- Intent
- opengl
- Android
- 배다해
- 뮤직비디오
- Eclipse
- 네트워크
- 네트워크보안
- 쓰레드
- HTML
- 레인보우
- 서비스
- 영어
- opencv
- Linux
- error
- 인텐트
- 바닐라루시
Archives
- Today
- Total
W.A 저장소
Android Spinner 본문
package com.karyu.androidstudy;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class AndroidStudyActivity extends Activity {
TextView selection;
String[] items = { "lorem", "ipsum", "dolor", "sit" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection = (TextView)findViewById(R.id.selection);
Spinner spin = (Spinner)findViewById(R.id.spinner);
spin.setOnItemSelectedListener(new SpinnerListen());
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, items);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
private class SpinnerListen implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
selection.setText(items[arg2]);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
selection.setText("");
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="@+id/TextView01"
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true">
</Spinner>
</LinearLayout>
'Programing' 카테고리의 다른 글
Layout 예제 1. (0) | 2010.08.04 |
---|---|
Android Database(Sqlite) Instruction (2) | 2010.07.29 |
Android CheckBox (0) | 2010.07.20 |
Programming Reference (0) | 2010.07.16 |
Screen Capture Class(화면 캡쳐 클래스) Robot (0) | 2010.07.16 |