[안드로이드,Android]스피너,Spinner
2013. 2. 6. 09:29ㆍMobile/Android
반응형
MainActivity.java
package com.example.ggari_spinner; 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.Toast; public class MainActivity extends Activity { ArrayAdapter<CharSequence> adspin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Spinner spinner = (Spinner) findViewById(R.id.spinner); spinner.setPrompt("시/도 를 선택하세요."); adspin = ArrayAdapter.createFromResource(this, R.array.selected, android.R.layout.simple_spinner_item); adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adspin); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(MainActivity.this, adspin.getItem(position) + "을 선택 했습니다.", 1).show(); } public void onNothingSelected(AdapterView<?> parent) { } }); } }activity_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:id="@+id/tv01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="스피너(spinner) 선택하세요" /> <Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>value -> array.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="selected"> <item>서울시</item> <iem>경기도</item> <item>강원도</item> <item>충청도</item> <item>전라도</item> <item>경상도</item> </string-array> </resources>
반응형
'Mobile > Android' 카테고리의 다른 글
[안드로이드,Android]종료 다이얼로그 (0) | 2013.02.08 |
---|---|
[안드로이드,Android]seekbar ,시크바 (0) | 2013.02.07 |
[안드로이드,Android]WebView,웹뷰 (1) | 2013.02.05 |
[안드로이드]프로그레스바,ProgressBar (0) | 2013.01.30 |
[안드로이드,Android]키보드 보이기, 숨기기 (0) | 2013.01.28 |