Example usage for android.database Cursor getCount

List of usage examples for android.database Cursor getCount

Introduction

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

Prototype

int getCount();

Source Link

Document

Returns the numbers of rows in the cursor.

Usage

From source file:curso.android.DAO.RespostaDAO.java

public static Resposta getPerguntaById(Resposta p) {
    Cursor cursor = null;
    try {/*from  w  ww  .j  a  v a  2s.  c  om*/

        cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE asw_id = " + p.getAsw_id(), null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("asw_id");
            int askIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int respostaIndex = cursor.getColumnIndex("asw_resposta");
            int nameIndex = cursor.getColumnIndex("user_name");
            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long ask = Long.valueOf(cursor.getString(askIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String resposta = cursor.getString(respostaIndex);
                String user_name = cursor.getString(nameIndex);

                Resposta answer = new Resposta();
                answer.setAsw_id(id);
                answer.setAsk_id(ask);
                answer.setUser_id(user);
                answer.setAsw_resposta(resposta);
                answer.setUser_name(user_name);

                return answer;

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

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

From source file:fr.mixit.android.io.RemoteSessionsHandler.java

private static boolean isSessionTagsUpdated(Uri uri, JSONArray tags, ContentResolver resolver)
        throws JSONException {
    final Cursor cursor = resolver.query(uri, TagsQuery.PROJECTION, null, null, null);
    try {/*from www . j  a  v  a  2s  .co  m*/
        if (!cursor.moveToFirst())
            return false;
        return cursor.getCount() != tags.length();
    } finally {
        cursor.close();
    }
}

From source file:curso.android.DAO.PerguntaDAO.java

public static Pergunta getPerguntaById(Pergunta p) {
    Cursor cursor = null;
    try {/*www . j av a2s .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:fr.mixit.android.io.RemoteSessionsHandler.java

private static boolean isSessionSpeakersUpdated(Uri uri, JSONArray speakers, ContentResolver resolver)
        throws JSONException {
    final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null);
    try {/*  www .  j  av a 2  s . c o m*/
        if (!cursor.moveToFirst())
            return false;
        return cursor.getCount() != speakers.length();
    } finally {
        cursor.close();
    }
}

From source file:net.ccghe.emocha.model.DBAdapter.java

public static ArrayList<String> getFilesFiltered(String filter) {
    ArrayList<String> result = new ArrayList<String>();
    Cursor c = sDB.query(TABLE_DOWNLOADS, new String[] { "path" }, filter, null, null, null, null);
    int numRows = c.getCount();
    Log.i(Constants.LOG_TAG, filter + " : " + numRows);
    for (int i = 0; i < numRows; i++) {
        c.moveToPosition(i);//from  w ww.  jav  a2  s  . co m
        result.add(c.getString(DL_COL_PATH));
        Log.i(Constants.LOG_TAG, i + " : " + c.getString(DL_COL_PATH));
    }
    c.close();
    return result;
}

From source file:im.delight.android.baselib.Social.java

/**
 * Returns a list of phone numbers for the contact with the given lookup ID
 *
 * @param lookupID the lookup ID to get the phone numbers for
 * @param context Context instance to get the ContentResolver from
 * @return CharSequence[] containing all phone numbers for the given contact
 *///from www  .ja va  2 s  . c  o  m
public static CharSequence[] getContactPhone(String lookupID, Context context) {
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER };
    String where = ContactsContract.Contacts.LOOKUP_KEY + " = ?";
    String[] selectionArgs = new String[] { lookupID };
    String sortOrder = null;
    Cursor result = context.getContentResolver().query(uri, projection, where, selectionArgs, sortOrder);
    String phone;
    if (result != null) {
        if (result.getCount() > 0) {
            CharSequence[] res = new CharSequence[result.getCount()];
            int i = 0;
            while (result.moveToNext()) {
                phone = result.getString(result.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                if (phone != null) {
                    res[i] = phone;
                    i++;
                }
            }
            result.close();
            return res;
        } else {
            result.close();
            return null;
        }
    } else {
        return null;
    }
}

From source file:im.delight.android.baselib.Social.java

/**
 * Returns a list of email addresses for the contact with the given lookup ID
 *
 * @param lookupID the lookup ID to get the email addresses for
 * @param context Context instance to get the ContentResolver from
 * @return CharSequence[] containing all email addresses for the given contact
 *///from  www  .  j  av a 2 s.  co m
public static CharSequence[] getContactEmail(String lookupID, Context context) {
    Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
    String[] projection = new String[] { ContactsContract.CommonDataKinds.Email.DATA };
    String where = ContactsContract.Contacts.LOOKUP_KEY + " = ?";
    String[] selectionArgs = new String[] { lookupID };
    String sortOrder = null;
    Cursor result = context.getContentResolver().query(uri, projection, where, selectionArgs, sortOrder);
    String email;
    if (result != null) {
        if (result.getCount() > 0) {
            CharSequence[] res = new CharSequence[result.getCount()];
            int i = 0;
            while (result.moveToNext()) {
                email = result.getString(result.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                if (email != null) {
                    res[i] = email;
                    i++;
                }
            }
            result.close();
            return res;
        } else {
            result.close();
            return null;
        }
    } else {
        return null;
    }
}

From source file:Main.java

public static String getAbsoluteImagePath(Activity context, Uri uri) {
    String imagePath = "";
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.managedQuery(uri, proj, // Which columns to
            // return
            null, // WHERE clause; which rows to return (all rows)
            null, // WHERE clause selection arguments (none)
            null); // Order-by clause (ascending by name)

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            imagePath = cursor.getString(column_index);
        }/*  w  ww.  j  ava 2 s.  c o m*/
    }

    return imagePath;
}

From source file:curso.android.DAO.RespostaDAO.java

public static List<Resposta> readAll() {
    Cursor cursor = null;
    try {/*  w w  w  .ja v  a 2  s.co  m*/
        List<Resposta> all = new ArrayList<Resposta>();

        cursor = Const.db.rawQuery("SELECT * FROM resposta", null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("asw_id");
            int askIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int respostaIndex = cursor.getColumnIndex("asw_resposta");
            int nameIndex = cursor.getColumnIndex("user_name");
            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long ask = Long.valueOf(cursor.getString(askIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String pergunta = cursor.getString(respostaIndex);
                String user_name = cursor.getString(nameIndex);

                Resposta asw = new Resposta();
                asw.setAsw_id(id);
                asw.setAsk_id(ask);
                asw.setUser_id(user);
                asw.setAsw_resposta(pergunta);
                asw.setUser_name(user_name);

                all.add(asw);

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

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

From source file:com.csipsimple.backup.SipProfileJson.java

public static JSONObject serializeSipProfile(Context context, SipProfile profile) {
    JSONObject jsonProfile = serializeBaseSipProfile(profile);
    JSONArray jsonFilters = new JSONArray();

    Cursor c = Filter.getFiltersCursorForAccount(context, profile.id);
    int numRows = c.getCount();
    c.moveToFirst();//  w w w.  j  a  va  2 s . com
    for (int i = 0; i < numRows; ++i) {
        Filter f = new Filter(c);
        try {
            jsonFilters.put(i, serializeBaseFilter(f));
        } catch (JSONException e) {
            Log.e(THIS_FILE, "Impossible to add fitler", e);
        }
        c.moveToNext();
    }
    c.close();

    try {
        jsonProfile.put(FILTER_KEY, jsonFilters);
    } catch (JSONException e) {
        Log.e(THIS_FILE, "Impossible to add fitlers", e);
    }

    return jsonProfile;
}