سؤال

In my program i use tab activity. In one tab located list view, i try to get data from my sqlite data base to that list view. I don't found errors in code, but my list view is empty. there is fragment code:

public static class DummySectionFragment extends Fragment implements LoaderCallbacks<Cursor>{

    public static final String ARG_SECTION_NUMBER = "section_number";
    public DummySectionFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_tracker,
                container, false);
        View v = inflater.inflate(R.layout.activity_tracker,
                container, false);
        createList();
        db = new DB(act);
        db.open();
        String[] from = new String[] {DB.COLUMN_NAME, DB.COLUMN_TIME};
        int[] to = new int[] { R.id.tvTextName, R.id.tvText_time};

        Cursor cursor = db.getAllData();

        scAdapter = new SimpleCursorAdapter(getActivity(), R.layout.item, cursor, from, to, 0);
        lvData = (ListView) v.findViewById(R.id.lvData);
        lvData.setAdapter(scAdapter);
        return rootView;
    }

    public void createList(){
    }

    @Override
    public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onLoaderReset(Loader<Cursor> arg0) {
        // TODO Auto-generated method stub

    }
}
هل كانت مفيدة؟

المحلول

You are not correctly using your class that implements LoaderCallbacks. You're attempting to do your db call and retrieve your cursor within your onCreateView() method. This totally defeats the purpose of the LoaderCallbacks implementation.

Do some googling and find some tutorials on how to properly do this. Also, look at the official Android Documentation for LoaderManager.LoaderCallbacks.

Here are a few for you to start with:

http://www.androiddesignpatterns.com/2012/07/understanding-loadermanager.html http://www.grokkingandroid.com/using-loaders-in-android/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top