2011-07-06 4 views
0

sqlite 데이터베이스의 데이터로 listview를 채우기 위해이 메서드를 사용합니다. 이 응용 프로그램이 시작될 때 예상대로 작동합니다 startManagingCursor를 두 번 호출하면 데이터가 사라집니다.

private void populateListView() { 
    Cursor showsCursor = mDbHelper.fetchAllSummaries(); 
    startManagingCursor(showsCursor); 

    // Create an array to specify the fields we want to display in the list 
    String[] from = new String[]{DbAdapter.SUMMARY_TITLE, DbAdapter.SUMMARY_DATE, DbAdapter.SUMMARY_SUMMARY}; 

    // and an array of the fields we want to bind those fields to 
    int[] to = new int[]{R.id.showtitle, R.id.showdate, R.id.showsummary}; 

    // Now create a simple cursor adapter and set it to display 
    SimpleCursorAdapter shows = 
      new SimpleCursorAdapter(this, R.layout.custom_row_view, showsCursor, from, to); 
    setListAdapter(shows); 
} 

그런 다음 나는 또한 업데이트 된 데이터로 목록보기를 채우기 위해 다시() 데이터베이스를 업데이트하고 populateListView를 호출하는 새로 고침 메뉴 항목이있다. 그것도 가 나타납니다 괜찮습니다.

정확하게는 아닙니다! 다른 활동 (예 : 목록보기 항목 중 하나를 클릭)을 시작한 다음 뒤로 버튼을 사용하여 되돌아 가면 목록보기가 비어 있습니다. populateListView()를 다시 호출하면 다시 작성되지만 다른 활동에서 리턴되면 다시 비게됩니다.

디버깅을 통해 startManagingCursor()를 생략하면 완벽하게 작동한다는 것을 알았습니다.

따라서 startManagingCursor()를 두 번 호출하면 예상치 못한 부작용이 발생할 수 있습니다. 왜 이런 일이 일어나고 어떻게 해결할 수 있습니까?

onCreate() 메서드가 아닌 startManagingCursor()를 호출하는 것이 잘못된 곳입니까? 그리고 한 번에 stopManagingCursor()를 실제로 호출해야합니까?

답변

1

startManagingCursor()를 호출하는 것이 onCreate() 메서드에 있어야할까요?

괜찮을 것입니다.

사실 한 번에 stopManagingCursor()를 호출해야합니까?

더 이상 Cursor 필요하지

(예를 들어, 당신이 그것을 교체) 관리 할 수, stopManagingCursor()를 호출합니다.

관련 문제