Click here to Skip to main content
15,902,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am trying to populate a listView from sqlite database in android using CustomCursor Adapter. The problem is that my listView shows nothing when I run the program. Just empty listview is displayed.

What I have tried:

package com.pass;


import android.app.ProgressDialog;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ListView;


/**
 * A simple {@link Fragment} subclass.
 */
public class SiteFragment extends Fragment {
    ListView allSites;
    ProgressDialog progressDialogue;
    Cursor cursor;

    public SiteFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_site, container, false);
        allSites = (ListView) view.findViewById(R.id.LIST_SITES);
        SiteCursorAdapter adapter = new SiteCursorAdapter(getActivity(), cursor);
        allSites.setAdapter(adapter);
        return view;
    }
    @Override
    public void onStart() {
        super.onStart();
        new FetchSitesAsynch().execute();
    }
    private class FetchSitesAsynch extends AsyncTask<Void, Void, Void>{

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressDialogue = new ProgressDialog(getActivity());
            progressDialogue.setTitle("Retrieving Sites Info");
            progressDialogue.setMessage("Please Wait...");
            progressDialogue.setCancelable(true);
            progressDialogue.setIndeterminate(true);

            progressDialogue.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            Database database = new Database(getActivity());
            //database.getAll();
            cursor = database.getAllSitesInfo();
            Log.d("Site Fetched", "Note");
            return null;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            if (progressDialogue != null)
                progressDialogue.dismiss(); // close dialog

        }
    }
}
Posted
Updated 10-Mar-17 2:35am
v2

1 solution

Hi you can see in my youtube video [Android studio]24. SQLite GetImage TakePicture - YouTube[^]
 
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