Android Open Source - forklift Canton List Fragment






From Project

Back to project page forklift.

License

The source code is released under:

Apache License

If you think the Android project forklift listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.forklift;
//  w ww.j  a va  2  s  . c  om
import android.app.ListFragment;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleCursorAdapter;

public class CantonListFragment extends ListFragment {

    private SimpleCursorAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        adapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item, null, new String[]{"name", "capital"},
                new int[]{R.id.name, R.id.description}, 0);

        setListAdapter(adapter);

        return inflater.inflate(R.layout.list, null);
    }

    @Override
    public void onResume() {
        super.onResume();

        new LoadDataTask().execute();
    }

    private class LoadDataTask extends AsyncTask<Void, Void, Cursor> {

        @Override
        protected Cursor doInBackground(Void... params) {
            CantonsAssetSqliteOpenHelper helper = new CantonsAssetSqliteOpenHelper(getActivity());
            SQLiteDatabase db = helper.getDatabase();

            SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
            builder.setTables("cantons");
            return builder.query(db, null, null, null, null, null, "_id");
        }

        @Override
        protected void onPostExecute(Cursor cursor) {
            adapter.changeCursor(cursor);
        }
    }
}




Java Source Code List

ch.gluecode.forklift.AbstractAssetSqliteOpenHelper.java
ch.gluecode.forklift.AbstractBundledSqliteOpenHelper.java
ch.gluecode.forklift.AbstractResourceSqliteOpenHelper.java
ch.gluecode.forklift.BundledSqliteOpenHelperException.java
com.example.forklift.CantonListFragment.java
com.example.forklift.CantonsAssetSqliteOpenHelper.java
com.example.forklift.MountainCursorAdapter.java
com.example.forklift.MountainListFragment.java
com.example.forklift.MountainsResourceSqliteOpenHelper.java
com.example.forklift.SampleActivity.java