2012-04-20 2 views
0

웹에서 Listview가 생성 된 sqlite 데이터베이스를 채우는 정보를로드하는 중 진행 대화 상자를 표시하려고합니다. 정보가 다운로드되는 동안 진행률 대화 상자를 표시하지만 이후에는 목록보기가 비어있는 비동기 클래스를 만들었습니다. 아마 listview가 비동기 전에로드되기 때문일 것입니다. 그렇다면 목록보기를 다시로드하거나 올바른 방법으로 어떻게 수행합니까?안드로이드 : 데이터베이스에서 비동기 적으로 채워진 후리스트 뷰로드하기

private class DownloadInfo extends AsyncTask <Void, Void, Void>{ 
    //////////////////Open Dialog before execution /////////// 
private ProgressDialog dialog; 
    protected void onPreExecute(){ 
     dialog = new ProgressDialog(CandidatesList.this); 
     dialog.setMessage("Loading Candidates from Webserver"); 
     dialog.setIndeterminate(true); 
     dialog.setCancelable(false); 
     dialog.show(); 
    } 
    ///////////////Background Processing////////////////// 
    @Override 
    protected Void doInBackground(Void... dbArray) { 
    ////Load information from webserver and put it in sqlite/// 
     return null; 

    } 

    ///////After the processing is done ////////////// 
    protected void onPostExecute(Void unused) { 
     dialog.dismiss(); 
    } 

} 

그리고가 다음입니다 만들 때 : : 여기 (이 displag 데 시간이 너무 오래이기 때문에 백그라운드 처리를 왼쪽으로) 지금까지 무엇을 가지고

DownloadInfo task = new DownloadInfo(); 
    task.execute(); 
Cursor c = db.getAllCandidates(); 
    candidates = new String[c.getCount()]; 
    if (c.moveToFirst()) { 
     int i = 0; 
     do { 
      candidates[i] = c.getString(1);// insert Name into candidate 
              // Array 
      i++; 
     } while (c.moveToNext()); 
    } 
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, 
      candidates)); 

이 도와주세요, 당신에게

감사

답변

1

데이터베이스의 커서 정보를 자동으로 ListView에로드하려면 ListView에 SimpleCursorAdapter을 사용하십시오. (비동기 완료 후 notifyDataSetChanged()를 호출해야 할 수도 있습니다.

+0

postExecute에서 notifyDataSetChanged()를 호출 하시겠습니까? 그리고 무엇에? – Diaa

+0

notifyDataSetChanged()는 SimpleCursorAdapter의 상속 된 메서드입니다. 한 가지 해결책은 AsyncTask를 어댑터에 전달하고 postExecute()에서 notifyDataSetChanged()를 호출하는 것입니다. – Sam

관련 문제