안드로이드 개발 질문/답변
(글 수 45,052)
아래 질문을 드렸는데, 또 드리네요;;
현재 만드려고 하는 페이지는 상단에 spinner가 하나 있고, 선택값에 따라 listview가 갱신 되는 형태입니다.
spinner와 listview는 SimpleCursorAdapter를 사용했습니다.
궁금한것에 대해 질문 드리겠습니다.
1. 아래와 같이 코드를 작성하였는 실제 화면에서 디비갯수 만큼 보여지기는 하는데, 아무 글자도 안나옵니다. 혹시 빠트린 부부분이 있는지요?
코드
String sp_sql = "SELECT _id, CAT1_NM FROM tbl_bj_info group by CAT1_NM"; sp_c = database.rawQuery(sp_sql, null); // 데이터를 spinner에 연결하기 String[] sp_from = new String[]{DBInfo.COLUMN_CAT1_NM}; int[] sp_to = new int[]{R.id.sp_cat1}; cursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, sp_c, sp_from, sp_to); cursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_cat1.setAdapter(cursorAdapter); sp_cat1.setOnItemSelectedListener(this); // OnItemSelectedListener를 implement했습니다.
2. spinner화면에서 (현재는 글자는 아무것도 보이지 않음) 아이템 선택시 curC.getString(1)을 출력 했을때 원하는 값은 받아 올수가 있습니다. 선택된 값에 따라 다시 쿼리를 날리고, listview를 업데이트 할려고 하는데, 아래 함수에 어떤 코드를 추가 하면 되는지요?
코드
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Cursor curC = (Cursor)sp_cat1.getSelectedItem(); curC.moveToPosition(position); Log.i("Test", " " + curC.getString(1)): // 원하는 값이 나옵니다. }