Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
okay, so after going through tons of sites and blogs I have finally decided to ask this 'not so FAQ'.

I have 2 listViews. One as the 'category LV' and other as the 'item LV'. The functionality is quite simple- When the user clicks a category cell in the 'category LV', all the items matching that category should filter and appear in the 'item LV'. I do this by assigning the 'category integer' to every item in the database. So, when a category is tapped its integer id is taken and all the ids matching with it in the item database are loaded in the cursor.

PROBLEM: I use the adapter.changeCursor(newCursor) method to change the underlying data in the adapter. According to the docs, this method replaces and closes the previously loaded cursor. I am getting this error

11-08 11:54:15.939: E/AndroidRuntime(2056): android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method.

Down below is the code explained:

Java
itemAdapter=new CategoryCursorAdapter(this, itemCursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER, "item_name",1,date,db);
    categoryLV.setOnItemClickListener(new AdapterView.OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            String s=((TextView)arg1.findViewById(R.id.category_name)).getText().toString();

            if(s.equalsIgnoreCase("all")){

                itemAdapter.changeCursor(null);
                itemAdapter.notifyDataSetChanged();
            }


            else{
            itemAdapter.changeCursor(db.getItemCursor(s));
            itemAdapter.notifyDataSetChanged();

            }



        }

    });


I get the error in the CursorAdapter class:

Java
public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    if(mcolumn==CATEGORY_LV){
    TextView tv=(TextView)view.findViewById(R.id.category_name);
        tv.setText(mCursor.getString(mCursor.getColumnIndex(mColumnName)));
        tv.setTextSize(20); 
    }

    if(mcolumn==ITEM_LV){
        TextView item=(TextView)view.findViewById(R.id.item_name);
        TextView stock=(TextView)view.findViewById(R.id.stock_status);

                   // I get the staleDataException at this place
        String s=mCursor.getString(mCursor.getColumnIndex(mColumnName));
        Button drag=(Button)view.findViewById(R.id.drag_button);
        LinearLayout lv=(LinearLayout)view.findViewById(R.id.layout);
        drag.setFocusable(false);
        item.setText(s);
        item.setTextSize(20);
        stock.setText("Stock:"+mdb.getStockStatus(mdb.getItemCode(s), mDate));
        stock.setTextSize(15);
    }
}


One thing to note here is that I am using the same Adapter class to power both the listViews. However i dont think this can be a problem.
Posted

1 solution

what is mCursor? How did you create it? why don't you use the parameter
Java
cursor
that from
Java
public void bindView(View view, Context context, Cursor cursor)
?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900