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:curso.android.DAO.PerguntaDAO.java

public static Pergunta getPerguntaById(Pergunta p) {
    Cursor cursor = null;
    try {//www.  j av a  2  s  .c o m

        cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE ask_id = " + p.getAsk_id(), null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int perguntaIndex = cursor.getColumnIndex("ask_pergunta");
            int nomeIndex = cursor.getColumnIndex("user_nome");

            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String pergunta = cursor.getString(perguntaIndex);
                String user_name = cursor.getString(nomeIndex);

                Pergunta ask = new Pergunta();
                ask.setAsk_id(id);
                ask.setUser_id(user);
                ask.setAsk_pergunta(pergunta);
                ask.setUser_name(user_name);

                return ask;

            } while (!cursor.isAfterLast());
        }

        return null;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:net.potterpcs.recipebook.IngredientsEditor.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    activity = (RecipeEditor) getActivity();
    ingredients = new ArrayList<String>();
    currentIngredient = -1;/*w  w  w .jav  a 2  s  .c  o m*/

    // Check for saved state and load it if needed
    if (savedInstanceState != null) {
        String[] saved = savedInstanceState.getStringArray(STATE);
        if (saved != null) {
            ingredients.addAll(Arrays.asList(saved));
        }
    } else {
        // No saved state, so we start a fresh editor
        long rid = activity.getRecipeId();
        //         Log.i(TAG, "id=" + rid);

        // If we're editing an existing recipe...
        if (rid > 0) {
            RecipeBook app = (RecipeBook) activity.getApplication();
            Cursor c = app.getData().getRecipeIngredients(rid);
            //            Log.i(TAG, "count=" + c.getCount());

            c.moveToFirst();
            while (!c.isAfterLast()) {
                //               Log.i(TAG, c.getString(c.getColumnIndex(RecipeData.IT_NAME)));
                ingredients.add(c.getString(c.getColumnIndex(RecipeData.IT_NAME)));
                c.moveToNext();
            }

            c.close();

        } else {
            // We're creating a new recipe, so no setup required (yet?)
        }
    }

    adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, ingredients);

    return inflater.inflate(R.layout.ingredientsedit, container, false);
}

From source file:com.pursuer.reader.easyrss.network.SubscriptionDataSyncer.java

private void syncSubscriptionIcons() throws DataSyncerException {
    final Context context = dataMgr.getContext();
    if (!NetworkUtils.checkSyncingNetworkStatus(context, networkConfig)) {
        return;/*from  ww w  .  j av a 2 s.  com*/
    }
    final ContentResolver resolver = context.getContentResolver();
    final Cursor cur = resolver.query(Subscription.CONTENT_URI,
            new String[] { Subscription._UID, Subscription._ICON, Subscription._URL }, null, null, null);
    for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) {
        final String uid = cur.getString(0);
        final byte[] data = cur.getBlob(1);
        final String subUrl = cur.getString(2);
        if (subUrl != null && data == null) {
            final SubscriptionIconUrl fetchUrl = new SubscriptionIconUrl(isHttpsConnection, subUrl);
            try {
                final byte[] iconData = httpGetQueryByte(fetchUrl);
                final Bitmap icon = BitmapFactory.decodeByteArray(iconData, 0, iconData.length);
                final int size = icon.getWidth() * icon.getHeight() * 2;
                final ByteArrayOutputStream output = new ByteArrayOutputStream(size);
                icon.compress(Bitmap.CompressFormat.PNG, 100, output);
                output.flush();
                output.close();
                dataMgr.updateSubscriptionIconByUid(uid, output.toByteArray());
            } catch (final IOException exception) {
                cur.close();
                throw new DataSyncerException(exception);
            }
        }
    }
    cur.close();
}

From source file:com.aboveware.sms.ui.MessageListAdapter.java

private boolean isCursorValid(Cursor cursor) {
    // Check whether the cursor is valid or not.
    if (cursor == null || cursor.isClosed() || cursor.isBeforeFirst() || cursor.isAfterLast()) {
        return false;
    }//from   ww  w  . j a  v a  2s.c  o m
    return true;
}

From source file:com.samknows.measurement.storage.TestResultDataSource.java

private List<TestResult> getTestResults(String selection, String limit) {
    List<TestResult> ret = new ArrayList<TestResult>();
    Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, SKSQLiteHelper.TABLE_TESTRESULT_ALLCOLUMNS,
            selection, null, null, null, order, limit);
    cursor.moveToFirst();/*from   ww  w  . j a va 2  s.  co  m*/
    while (!cursor.isAfterLast()) {
        ret.add(cursorToTestResult(cursor));
        cursor.moveToNext();
    }
    cursor.close();
    return ret;
}

From source file:it.ms.theing.loquitur.functions.Storage.java

/**
 * Get a list of keys and related values
 * @param genre/*from   ww  w.j av a  2s  .  c o m*/
 * The genre of the key
 * @return
 * a string conaining a json array of json objects structure :
 * [ { key:<name>, value:<value>} , ... ]
 */

@JavascriptInterface
public String getList(String genre) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=?",
            new String[] { genre.toUpperCase() });
    cursor.moveToFirst();
    JSONArray ja = new JSONArray();
    while (!cursor.isAfterLast()) {
        JSONObject jo = new JSONObject();
        try {
            jo.put("key", cursor.getString(1));
            jo.put("value", cursor.getString(2));
        } catch (JSONException e) {
        }
        ja.put(jo);
        cursor.moveToNext();
    }
    return ja.toString();
}

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

private int[] getPorts(long cookieId) {
    List<Integer> ports = new ArrayList<Integer>();

    Cursor cursor = db.query(CookieSQLHelper.PORT_TABLE_NAME, null, CookieSQLHelper.COLUMN_COOKIE_ID + "=?",
            new String[] { Long.toString(cookieId) }, null, null, null, null);
    cursor.moveToFirst();//from  w w w .j a va  2  s.  c o m

    while (!cursor.isAfterLast()) {
        ports.add(cursor.getInt(cursor.getColumnIndex(CookieSQLHelper.COLUMN_PORT)));
        cursor.moveToNext();
    }

    cursor.close();

    int[] arrayPorts = new int[ports.size()];
    for (int i = 0; i < ports.size(); i++) {
        arrayPorts[i] = ports.get(i);
    }

    return arrayPorts;
}

From source file:it.ms.theing.loquitur.functions.Storage.java

public Vector<Pair<String[], String>> loadCache(String name) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=?", new String[] { name });
    cursor.moveToFirst();//from  w  w w . j a v a 2  s  .c  o  m
    Vector<Pair<String[], String>> ja = new Vector<Pair<String[], String>>();
    while (!cursor.isAfterLast()) {
        String[] sv = cursor.getString(1).split("\'| ");
        String s = cursor.getString(2);
        Pair<String[], String> p = Pair.create(sv, s);
        ja.add(p);
        cursor.moveToNext();
    }
    return ja;
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    data.moveToFirst();//from   w  w w.  j a  v a 2  s. c  o  m
    if (!data.isAfterLast())
        suggestedName = data.getString(0);
}

From source file:com.earthblood.tictactoe.activity.GameActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    int[] XIds = new int[9];
    int countX = 0;
    int[] OIds = new int[9];
    int countO = 0;

    data.moveToFirst();// w  w  w  . j  av  a2 s.  c  o  m

    while (data.isAfterLast() == false) {

        int boxId = data.getInt(1);
        int gameSymbolId = data.getInt(2);

        if (GameSymbol.X.getId() == gameSymbolId) {
            XIds[countX++] = boxId;
        } else {
            OIds[countO++] = boxId;
        }
        Button button = (Button) gridLayout.findViewById(GameBox.byLayoutId(boxId).layoutBoxId());
        button.setText(GameSymbol.byId(gameSymbolId).getValue());
        button.setEnabled(false);
        data.moveToNext();
    }
    if (toeGame.inProgress()) {
        endTurn(XIds, OIds, data.getCount());
    }
}