반응형
public class SpinnerHandler extends Thread{ private String[] arrayClassfy, arrayCause, arrayType, arrayDepartment; /* 서버에서 스피너 데이터 가져오는 부분 */ private void getSpinnerAttibute() { String[] arrayClassfy = {"class1", "class2", "class3"}; String[] arrayCause = {"cause1", "cause2", "cause3"}; String[] arrayType = {"type1", "type2", "type3"}; String[] arrayDepartment = {"department1", "department2", "department3"}; this.arrayClassfy = arrayClassfy; this.arrayCause = arrayCause; this.arrayType = arrayType; this.arrayDepartment = arrayDepartment; } /* 스피너 세팅을 위한 메소드 */ public ArrayAdaptersetAutoAdapter(Context context, String pWhat) { String[] items = null; getSpinnerAttibute(); if(pWhat.equals("Classfy")) items = arrayClassfy; else if(pWhat.equals("Type")) items = arrayType; else if(pWhat.equals("Cause")) items = arrayCause; else if(pWhat.equals("Department")) items = arrayDepartment; ArrayAdapter adapter = new ArrayAdapter ( context, android.R.layout.simple_dropdown_item_1line, items); adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); return adapter; } public String[] getClassfy() { return this.arrayClassfy; } public String[] getCause() { return this.arrayCause; } public String[] getType() { return this.arrayType; } public String[] getDepartment() { return this.arrayDepartment; } } /** * 스피너를 클릭했을 때 클릭한 아이템 값을 저장하는 클래스 * @author DervelJunNote */ class SpinListener implements OnItemSelectedListener{ public void onItemSelected(AdapterView parents, View v, int position, long id) { if(spinClassfy.getId() == parents.getId()) selectClassfy = arrayClassfy[position]; else if(spinType.getId() == parents.getId()) selectType = arrayType[position]; else if(spinCause.getId() == parents.getId()) selectCause = arrayCause[position]; else if(spinDepartment.getId() == parents.getId()) selectDepartment = arrayDepartment[position]; } public void onNothingSelected(AdapterView parents) { if(spinClassfy.getId() == parents.getId()) selectClassfy = ""; else if(spinType.getId() == parents.getId()) selectType = ""; else if(spinCause.getId() == parents.getId()) selectCause = ""; else if(spinDepartment.getId() == parents.getId()) selectDepartment = ""; } }
반응형
'Android' 카테고리의 다른 글
OnCheckedChangeListener 모양 (0) | 2013.01.31 |
---|---|
뒤로가기 버튼 (0) | 2013.01.30 |
커스텀 리스트 뷰 CustomListView (0) | 2013.01.30 |
자주 쓰는 메소드 : goOtherActivity, setActivity, setListener, warmToast (0) | 2013.01.30 |
토스트 Toast (0) | 2013.01.30 |
WRITTEN BY
,