0

I have the following fragment:

public class Tab3Fragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {

    private static final int LOADER_ID = 42;
    private CursorAdapter _adapter;


    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
        _adapter.notifyDataSetChanged();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        _adapter.notifyDataSetChanged();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.tab3_frag, container, false);

        ListView lv = view.findViewById(R.id.student_view);
        _adapter = new SimpleCursorAdapter(getContext(),
                R.layout.container_list_item_view, null,
                new String[] { Contract.Student_Table.STUDENTS_COLUMN_NAME_NOID},
                new int[] { R.id.list_item });
        lv.setAdapter(_adapter);
        getActivity().getLoaderManager().restartLoader(LOADER_ID, null, this);

        return view;
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        if (id != LOADER_ID) {
            return null;
        }
        return new CursorLoader(getContext(),
                Contract.Student_Table.CONTENT_URI,
                new String[] { Contract.Student_Table.STUDENTS_COLUMN_ID, Contract.Student_Table.STUDENTS_COLUMN_NAME_NOID}, null, null,
                null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        _adapter.changeCursor(data);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        _adapter.swapCursor(null);
    }
}

However, whenever I rotate the screen, the content is removed from the display. I have overridden the functions that were necessary,I've tried changing initLoader to restartLoader and interchanging swapCursor for changeCursor, but I can't seem to find what the issue is.

Can anyone identify the issue is and could point it out so that I can fix it?

Thanks

Jon Goe
  • 165
  • 2
  • 13

0 Answers0