Example usage for android.database Cursor isAfterLast

List of usage examples for android.database Cursor isAfterLast

Introduction

In this page you can find the example usage for android.database Cursor isAfterLast.

Prototype

boolean isAfterLast();

Source Link

Document

Returns whether the cursor is pointing to the position after the last row.

Usage

From source file:fr.eoit.activity.EOITActivity.java

@Override
public void onLoadFinished(Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor)) {

        while (!cursor.isAfterLast()) {

            cursor.moveToNext();/* w w w .ja v a 2  s . c o  m*/
        }
    }
}

From source file:org.egov.android.data.SQLiteHelper.java

public JSONArray query(String sql) {
    JSONArray data = new JSONArray();
    JSONObject row = null;//from  ww w.  java  2  s .c  o  m
    Cursor cursor = query(sql, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        row = new JSONObject();
        int cc = cursor.getColumnCount();
        for (int i = 0; i < cc; i++) {
            try {
                row.put(cursor.getColumnName(i), cursor.getString(i));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        data.put(row);
        cursor.moveToNext();
    }
    cursor.close();
    return data.length() == 0 ? null : data;
}

From source file:com.ruuhkis.cookies.CookieSQLSource.java

/**
 * /*  w  w  w.  java2 s . com*/
 * @return a list of all cookies stored in cookies table
 */

public List<SQLCookie> getCookies() {
    List<SQLCookie> cookies = new ArrayList<SQLCookie>();
    Cursor cursor = db.query(CookieSQLHelper.COOKIE_TABLE_NAME, null, null, null, null, null, null);
    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
        cookies.add(cursorToCookie(cursor));
        cursor.moveToNext();
    }

    cursor.close();

    return cookies;
}

From source file:edu.asu.bscs.csiebler.waypointdatabase.MainActivity.java

private JSONArray getJsonResults() {
    JSONArray resultSet = new JSONArray();

    try {/*from   w w  w . jav a2s  . co m*/
        WaypointDB db = new WaypointDB(this);
        db.copyDB();
        SQLiteDatabase waypointDB = db.openDB();
        waypointDB.beginTransaction();

        String searchQuery = "SELECT  * FROM waypoint";
        Cursor cursor = waypointDB.rawQuery(searchQuery, null);

        cursor.moveToFirst();

        while (cursor.isAfterLast() == false) {
            int totalColumn = cursor.getColumnCount();
            JSONObject rowObject = new JSONObject();

            for (int i = 0; i < totalColumn; i++) {
                if (cursor.getColumnName(i) != null) {
                    try {
                        if (cursor.getString(i) != null) {
                            Log.d("TAG_NAME", cursor.getString(i));
                            rowObject.put(cursor.getColumnName(i), cursor.getString(i));
                        } else {
                            rowObject.put(cursor.getColumnName(i), "");
                        }
                    } catch (Exception e) {
                        Log.d("TAG_NAME", e.getMessage());
                    }
                }
            }

            resultSet.put(rowObject);
            cursor.moveToNext();
        }

        cursor.close();
        waypointDB.endTransaction();
        waypointDB.close();
        db.close();

        Log.d("TAG_NAME", resultSet.toString());
    } catch (Exception ex) {
        Log.w(getClass().getSimpleName(), "Exception creating adapter: " + ex.getMessage());
    }

    return resultSet;
}

From source file:org.sociotech.fishification.ui.fragments.CreateFishFragment.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {

    String userName = null;/*from  www  .  ja va2 s.c om*/
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {

        if (cursorLoader.getId() == 0) {

            userName = cursor.getString(ProfileQuery.DISPLAY_NAME);

        } else {
            userName = cursor.getString(ProfileQuery.ADDRESS);
        }
    }

    if (userName != null && !userName.isEmpty()) {

        // Set UserName
        setEditText(R.id.authorNameText, userName);

    } else if (cursorLoader.getId() == 0) {

        // Select primary e-mail address
        getActivity().getSupportLoaderManager().initLoader(1, null, this);

    } else {

        // Parse accounts for user name or e-mail address
        AccountManager am = AccountManager.get(getActivity());
        Account[] accounts = am.getAccountsByType("XING");
        if (accounts != null && accounts.length > 0) {
            setEditText(R.id.authorNameText, accounts[0].name);
        } else {
            accounts = am.getAccounts();
            if (accounts != null && accounts.length > 0) {
                setEditText(R.id.authorNameText, accounts[0].name);
            }
        }
    }
}

From source file:com.kynetx.api.java

public void setApp(Cursor apps) {
    appId = "";//from  w ww .j  a  v  a 2  s  . co  m
    appVersions = "";

    apps.moveToFirst();

    while (apps.isAfterLast() == false) {
        if (!apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_VERSION)).equals("none")) {
            appId += apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_APPID));
            appVersions += appId + ":kynetx_app_version="
                    + apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_VERSION)) + "&";
            if (!apps.isLast()) {
                appId += ";";
            }
        }
        apps.moveToNext();
    }
    apps.close();
}

From source file:com.amaze.filemanager.activities.DbViewer.java

private ArrayList<String> getDbTableNames(Cursor c) {
    ArrayList<String> result = new ArrayList<String>();
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        for (int i = 0; i < c.getColumnCount(); i++) {
            result.add(c.getString(i));/*from  ww  w.j av  a 2s  . c  om*/
        }
    }
    return result;
}

From source file:fr.eoit.activity.fragment.mining.session.AddItemToCargoDialog.java

@Override
public void onLoadFinished(Cursor cursor) {

    asteroids = new SparseItemBeanArray();

    if (DbUtil.hasAtLeastOneRow(cursor)) {
        while (!cursor.isAfterLast()) {
            ItemBeanWithMaterials item = ItemUtil.getItem(cursor, 1,
                    EOITConst.Categories.ASTEROID_CATEGORIE_ID);

            item.id = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID));
            asteroids.append(item);/*from www .jav  a2 s.c  o  m*/

            cursor.moveToNext();
        }
    }

    cursor.moveToFirst();

    adapter.swapCursor(cursor);
}

From source file:fr.eoit.parameter.Parameters.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor) && loader.getId() == PARAM_LOADER_ID) {

        while (!cursor.isAfterLast()) {
            int paramId = cursor.getInt(cursor.getColumnIndexOrThrow(Parameter._ID));
            String paramValue = cursor
                    .getString(cursor.getColumnIndexOrThrow(Parameter.COLUMN_NAME_PARAM_VALUE));

            switch (paramId) {
            // no more used.
            case EOITConst.PARAM_USER_ID_ID:
            case EOITConst.PARAM_API_KEY_ID:
            case EOITConst.PARAM_CHARACTER_ID_ID:
            case EOITConst.PARAM_TRADE_STATION_ID:
            case EOITConst.PARAM_PROD_STATION_ID:
                break;

            default:
                Skills.initSkill(paramId, Short.parseShort(paramValue));
                break;
            }//from w  w  w .j a v  a  2 s  .  c  o m
            cursor.moveToNext();
        }
    }

    if (DbUtil.hasAtLeastOneRow(cursor) && loader.getId() == STATIONS_LOADER_ID) {

        parseStationCursor(cursor);
    }
}

From source file:org.disrupted.rumble.database.statistics.StatisticDatabase.java

public JSONArray getJSON() {
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    Cursor cursor = database.query(getTableName(), null, null, null, null, null, null);
    if (cursor == null)
        return null;
    JSONArray resultSet = new JSONArray();
    try {//  ww  w .  j av a  2  s  . co m
        cursor.moveToFirst();
        while (cursor.isAfterLast() == false) {
            int totalColumn = cursor.getColumnCount();
            JSONObject rowObject = new JSONObject();
            for (int i = 0; i < totalColumn; i++) {
                if (cursor.getColumnName(i) != null) {
                    try {
                        if (cursor.getString(i) != null)
                            rowObject.put(cursor.getColumnName(i), cursor.getString(i));
                        else
                            rowObject.put(cursor.getColumnName(i), "");
                    } catch (Exception e) {
                    }
                }
            }
            resultSet.put(rowObject);
            cursor.moveToNext();
        }
        cursor.close();
    } finally {
        cursor.close();
    }
    return resultSet;
}