2012-03-05 2 views
0

내 앱에 강의 목록이있는 Listview가 있습니다.StaleDataException : 재개시 ListView를 닫을 때 커서가 닫혔습니다.

cursor = myDbHelper.getReadableDatabase().rawQuery(sql, null);  
startManagingCursor(cursor); 
adapter = new Lectures_Adapter(this,R.layout.menu_item,cursor,FROM,TO);   
menuList.setAdapter(adapter); 

내 사용자 지정 어댑터의 코드는 - - 그들은 색상 종류에 따라 코딩, 나는이 작업을 수행하는 데 사용하는 사용자 정의 어댑터는 다음 코드에 의해 호출된다

public class Lectures_Adapter extends SimpleCursorAdapter { 
    private Context appContext; 
    private int layout; 
    private Cursor mycursor; 

    public Lectures_Adapter(Context context, int layout, Cursor c, String[] from,int[] to) { 
      super(context, layout, c, from, to); 
      this.appContext=context; 
      this.layout=layout; 
      this.mycursor=c;    
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent)  
    { 
      View view = super.getView(position, convertView, parent); 
      try {    
      if (position > 0) 
      {    
       RelativeLayout rowFill = (RelativeLayout) convertView.findViewById(R.id.rowFill); 
       String title = mycursor.getString(1);     
       int myColor = 0; 
       int myPos = title.indexOf("Nursing"); 
       int myPos2 = title.indexOf("Masterclass"); 
       if (myPos >= 0) 
       { 
        myColor = Color.parseColor("#99FF66"); 
       } 
       else if (myPos2 >= 0) 
       { 
        myColor = Color.parseColor("#FF99FF"); 
       } 
       else 
       { 
        myColor = Color.parseColor("#FFFF66"); 
       } 
       convertView.findViewById(R.id.rowFill).setBackgroundColor(myColor);     
       }   
      }catch(Exception e) { 

      } 

      if (convertView == null) { 
       LayoutInflater inflator = (LayoutInflater) this.appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       convertView = inflator.inflate(this.layout,null); 
      } else { 
       convertView = (View) convertView; 
      } 
      return view; 
     } 

    } 

나는 버튼이있는 네 가지 방법으로 Listview를 재정렬하는 옵션을 제공하는 대화 상자를 표시합니다. 그들은 내가 다시 주문 옵션 목록보기를 다음 코드를 사용하여 선택했을 때 -이 모두가 내가하고 위의 코드를 다시 주문하는 경우를 제외하고, 확인을 작동하는 것 같다

 Cursor newCursor = myDbHelper.getReadableDatabase().rawQuery(sqlStr, null); 
     adapter.changeCursor(newCursor);     
     adapter.notifyDataSetChanged(); 

그것을 내가 얻을의 getView를 실행할 때,라고 다음 오류 'StaleDataException : 액세스 닫힌 커서'. 커서가 닫혀 있기 때문에 문제가되지 않습니다. 무엇을 잘못 했습니까?

답변

0

getCursor()를 사용하여 현재 커서 값을 가져올 때 문제가 해결되었습니다.

관련 문제