0

데이터베이스에서 데이터를 가져 와서 listview에 채 웁니다. 난()이 데이터가 존재하지만 목록보기 아무것도 보여 cursor.count을 통해 확인했다 : 나는 SDCARD에서 사진을 얻을 수있는 방법SimpleCursorAdapter를 사용하여 데이터베이스에서 listview를 채우는 방법

rubDb.open(); 
    cur = rubDb.getRubParent();  
    startManagingCursor(cur); 
    Log.d("cursor length",Integer.toString(cur.getCount())); 
    String[] from = new String[] { RubriqueDbAdapter.RUB_NOM, RubriqueDbAdapter.RUB_VISUEL };  
    int[] to = new int[] {R.id.title, R.id.icon}; 
    listAdapter = new SimpleCursorAdapter(this, R.layout.itemgauche, cur, from, to); 
    listeGauche.setAdapter(listAdapter); 


public Cursor getRubParent() {    
    Cursor cursorResults = mDb.rawQuery("SELECT * FROM " + TABLE_RUBRIQUE + " WHERE rub_id_parent = 0 ORDER BY rub_ordre ASC", null);  
    return cursorResults; 
} 

과에 넣어 : 나는 simpleCursorAdapter을 사용/

을 이미지 뷰를 listview에?

도움 주셔서 감사합니다.

+0

어댑터 클래스에서 getView() 메소드를 게시하십시오. – FoamyGuy

+0

getView()를 오버라이드하지 않았습니다 : s – Remy

+0

좋아, ArrayAdapter, getView() 메소드를 확장하는 customlistadapter를 만들지 만 지금 데이터베이스에서 올바른 제목 추출로 setText를 만드는 방법은 무엇입니까? tx – Remy

답변

1

먼저 ArrayAdapter을 사용하기 위해 모든 데이터를 배열의 개체로 수동으로 복사하는 대신 CursorAdapter (아마도 SimpleCursorAdapter)을 사용해야합니다. 목록은 텍스트의 단순한 조각이 아닌 다른 아무것도 될 것입니다 경우

둘째, 당신은 당신이 원하는 어떤 다른 수행하는 방법 어댑터를 가르 칠해야합니다. SimpleCursorAdapter으로 ViewBinder을 연결하거나 SimpleCursorAdapter을 서브 클래 싱하고 setViewImage()을 오버라이드하거나 SimpleCursorAdapter 서브 클래스를 지정하고 bindView()을 오버라이드 할 수 있습니다.

+0

글쎄 ... 조금 어려울 것 같습니다. – Remy

+0

@Remy : 이미 작성한 코드보다 코드가 적습니다. – CommonsWare

+0

나는 이것을 시도 할 것이다 ... 고맙다. – Remy

관련 문제