Update SimpleCursorAdapter while maintaining scroll position in ListView

前端 未结 2 1225
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 08:22

My problem: My ListView resets its scroll position to the top whenever I update its contents through its (customized) SimpleCursorAdapter. I would like the ListView to main

2条回答
  •  生来不讨喜
    2021-01-02 08:57

    Did the same in post execute of Async Task used following code worked for me

     Cursor cursor = mDataHelper.getWritableDatabase().query(
                            DataContract.Incares.TABLE_NAME,  // Table to Query
                            null, // all columns
                            null, // Columns for the "where" clause
                            null, // Values for the "where" clause
                            null, // columns to group by
                            null, // columns to filter by row groups
                            DataContract.Incares.UUID +" DESC" // sort order
                    );
    CursorAdapter.swapCursor(cursor);
    CursorAdapter.notifyDataSetChanged();
    

    with CursorAdapter being a global variable

提交回复
热议问题