SPRING :: NOTE
[android] 한 메소드로 Spinner 여러개 사용하기 본문
<pre><code class="java">public class Info extends Activity {
ArrayAdapter<CharSequence> adspin;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
spinner((Spinner)findViewById(R.id.spinner1) ,R.array.open);
}
public void spinner(Spinner sp, int textArrayResId) {
adspin = ArrayAdapter.createFromResource(this, textArrayResId,
android.R.layout.simple_spinner_item);
adspin.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adspin);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(Info.this,
adspin.getItem(position) + "을/를 선택 했습니다.",
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
</code></pre>
'Development Language > JAVA · ANDROID' 카테고리의 다른 글
[android] selector로 버튼 액션 이미지 변경 (0) | 2016.06.10 |
---|---|
[android] 슬라이딩 메뉴 - SimpleSideDrawer (0) | 2016.06.10 |
[android] startActivityForResult 값 주고받기. (0) | 2016.06.10 |
[android] 커스텀 다이얼로그 만들기 (0) | 2016.06.10 |
[ANDROID] C서버와 소켓통신 (0) | 2016.06.09 |