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


Java Cursor.getString方法代碼示例

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


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

示例1: DownloadInfo

import android.database.Cursor; //導入方法依賴的package包/類
public DownloadInfo(Cursor cursor) {
    int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
    status = cursor.getInt(columnIndex);

    int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
    reason = cursor.getInt(columnReason);

    int columnBytesDownloadedSoFar = cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR);
    bytesDownloadedSoFar = cursor.getLong(columnBytesDownloadedSoFar);

    int columnId = cursor.getColumnIndex(DownloadManager.COLUMN_ID);
    enquId = cursor.getLong(columnId);

    int columnTitlle = cursor.getColumnIndex(DownloadManager.COLUMN_TITLE);
    title = cursor.getString(columnTitlle);

    int columnTimeStamp = cursor.getColumnIndex(DownloadManager.COLUMN_LAST_MODIFIED_TIMESTAMP);
    lastModifiedTimestamp = cursor.getLong(columnTimeStamp);

    int columnTotlalSize = cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES);
    totalSizeBytes = cursor.getLong(columnTotlalSize);

}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:24,代碼來源:DownloadInfo.java

示例2: getDataColumn

import android.database.Cursor; //導入方法依賴的package包/類
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            final int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:20,代碼來源:CroperinoFileUtil.java

示例3: getCurrentFuelPriceForGiven

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * use this function to get the Fuel price of current day
 * @param context context of this is running in
 * @param towncode towncode of town you want to get fuel price
 * @param isDiesel <code>true</code> if you want to know diesel price else <code>false</code>
 *                for petrol price
 * @param columnName name of column from which you want to retrieve data
 *                    pass null to get the data from column containing price of current day.
 * @return <code>isDiesel?currentDieselPrice:currentPetrolPrice</code>
 */
public static String getCurrentFuelPriceForGiven(Context context, String towncode, boolean isDiesel,
                                                 String columnName) {
    if(columnName == null) {
        columnName = getCurrentDay();
    }
    SQLiteDatabase db = getReadableDatabase(context);
    String selectionArgs[] = {towncode};
    final String TABLE_NAME = isDiesel?HpclDieselPriceTable.NAME:HpclPetrolPriceTable.NAME;
    final String[] PROJECTION = {PriceBaseTable.COLUMN_TOWN_CODE, columnName};
    Cursor data = db.query(TABLE_NAME, PROJECTION, PriceBaseTable.COLUMN_TOWN_CODE
            + "=?", selectionArgs, null, null, null);
    if(data != null) {
        data.moveToFirst();
        String price = data.getString(1);
        data.close();
        return price; // magic number based on table projection
    }
    return null;
}
 
開發者ID:andy1729,項目名稱:FuelFriend,代碼行數:30,代碼來源:DatabaseHelper.java

示例4: selectDB

import android.database.Cursor; //導入方法依賴的package包/類
public void selectDB() {
    noteList = new ArrayList<>();
    Cursor cursor = mDatabase.query(NoteDB.TABLE_NAME, null, null, null, null, null, sortOrder);
    while (cursor.moveToNext()) {
        String title = cursor.getString(cursor.getColumnIndex("title"));
        String content = cursor.getString(cursor.getColumnIndex("content"));
        Long time = cursor.getLong(cursor.getColumnIndex("time"));
        int id = cursor.getInt(cursor.getColumnIndex("id"));
        Post note = new Post(title, content, time, id);
        noteList.add(note);
    }
    noteAdapter = new NoteAdapter(this, noteList);
    mMenuRecyclerView.setLayoutManager(new LinearLayoutManager(this));//布局管理器
    mMenuRecyclerView.addItemDecoration(new ListViewDecoration(this));//添加分割線
    mMenuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
    //設置菜單item點擊監聽
    mMenuRecyclerView.setSwipeMenuItemClickListener(mOnSwipeMenuItemClickListener);
    noteAdapter.setOnItemClickListener(mOnItemClickListener);
    mMenuRecyclerView.setAdapter(noteAdapter);
    cursor.close();
}
 
開發者ID:weimin96,項目名稱:shareNote,代碼行數:22,代碼來源:NoteActivity.java

示例5: getAllStations

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * Get a list of all stations
 */
public List<Station> getAllStations() {
    List<Station> listOfAllStations = new ArrayList<Station>();

    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_STATIONS;
    Cursor c = db.rawQuery(query, null);
    while(c.moveToNext()) {
        Station entry = new Station(
                c.getString(c.getColumnIndex(COLUMN_ID_SERVER)),
                c.getString(c.getColumnIndex(COLUMN_NAME)),
                c.getString(c.getColumnIndex(COLUMN_LOCATION)),
                c.getInt(c.getColumnIndex(COLUMN_BIKESAVAILABLE)),
                c.getFloat(c.getColumnIndex(COLUMN_LATITUDE)),
                c.getFloat(c.getColumnIndex(COLUMN_LONGITUDE)),
                c.getFloat(c.getColumnIndex(COLUMN_CLIENT_DISTANCE))
        );
        listOfAllStations.add(entry);
    }

    db.close();
    c.close();
    return listOfAllStations;
}
 
開發者ID:carlosfaria94,項目名稱:UbiBike-client,代碼行數:27,代碼來源:MyDBHandler.java

示例6: testCreateDb

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * Tests that the database exists and the quotes table has the correct columns.
 */
@Test
public void testCreateDb() throws Exception {
    // build a HashSet of all of the table names we wish to look for
    // Note that there will be another table in the DB that stores the
    // Android metadata (db version information)
    final HashSet<String> tableNameHashSet = new HashSet<>();
    tableNameHashSet.add(FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL);
    tableNameHashSet.add(FavoritesContract.FavoriteColumns.FAVORITE_TV_SHOWS_TBL);
    tableNameHashSet.add(FavoritesContract.FavoriteColumns.FAVORITE_PERSON_TBL);

    Context appContext = InstrumentationRegistry.getTargetContext();
    appContext.deleteDatabase(FavoritesDbHelper.DATABASE_NAME);
    SQLiteDatabase db = new FavoritesDbHelper(appContext).getWritableDatabase();
    assertEquals(true, db.isOpen());

    // have we created the tables we want?
    Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);

    assertTrue("Error: This means that the database has not been created correctly",
            c.moveToFirst());

    // verify that the tables have been created
    do {
        tableNameHashSet.remove(c.getString(0));
    } while( c.moveToNext() );

    // if this fails, it means that your database doesn't contain the tables
    assertTrue("Error: Your database was created without the tables", tableNameHashSet.isEmpty());

    // now, do our tables contain the correct columns?
    c = db.rawQuery("PRAGMA table_info(" + FavoritesContract.FavoriteColumns.FAVORITE_MOVIES_TBL + ")", null);
    assertTrue("Error: This means that we were unable to query the database for table information.",
            c.moveToFirst());

    // Build a HashSet of all of the column names we want to look for
    final HashSet<String> locationColumnHashSet = new HashSet<>();
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns._ID);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_MOVIE_ID);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_TITLE);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_PLOT);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_POSTER_PATH);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_YEAR);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_DURATION);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_VOTE_AVERAGE);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_VOTE_COUNT);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_BACKGROUND_PATH);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_ORIGINAL_LANGUAGE);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_STATUS);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_IMDB_ID);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_BUDGET);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_REVENUE);
    locationColumnHashSet.add(FavoritesContract.FavoriteColumns.COLUMN_HOMEPAGE);

    int columnNameIndex = c.getColumnIndex("name");
    do {
        String columnName = c.getString(columnNameIndex);
        locationColumnHashSet.remove(columnName);
    } while(c.moveToNext());

    c.close();
    // if this fails, it means that your database doesn't contain all of the required columns
    assertTrue("Error: The database doesn't contain all of the required columns",
            locationColumnHashSet.isEmpty());
    db.close();
}
 
開發者ID:an-garcia,項目名稱:MovieGuide,代碼行數:69,代碼來源:TestDB.java

示例7: loadHeaderFromHeadersTable

import android.database.Cursor; //導入方法依賴的package包/類
private static MimeHeader loadHeaderFromHeadersTable(SQLiteDatabase db, long messageId) {
    Cursor headersCursor = db.query("headers",
            new String[] { "name", "value" },
            "message_id = ?", new String[] { Long.toString(messageId) }, null, null, null);
    try {
        MimeHeader mimeHeader = new MimeHeader();
        while (headersCursor.moveToNext()) {
            String name = headersCursor.getString(0);
            String value = headersCursor.getString(1);
            mimeHeader.addHeader(name, value);
        }
        return mimeHeader;
    } finally {
        headersCursor.close();
    }
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:17,代碼來源:MigrationTo51.java

示例8: getFirstPath

import android.database.Cursor; //導入方法依賴的package包/類
String getFirstPath(){

        String searchString = MediaStore.Audio.Media.IS_MUSIC + "=?" + "AND " + MediaStore.Audio.Media.ARTIST_ID + " = " + data[1];
        String[] searchPram = new String[]{"1"};
        String[] cols = new String[] {MediaStore.Audio.Media.DATA};
        Cursor cursor = Ui.ef.getBaseContext().getContentResolver().query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,cols, searchString  ,searchPram,null);



        for (int i = 0; i < cursor.getCount(); i++) {
            cursor.moveToNext();
            return  cursor.getString(0);
        }
        cursor.close();
        return  null;

    }
 
開發者ID:KishanV,項目名稱:Android-Music-Player,代碼行數:18,代碼來源:artitstBtns.java

示例9: buildAlbumCover

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * get the cover and count
 *
 * @param buckId album id
 */
private void buildAlbumCover(ContentResolver cr, String buckId, AlbumEntity album) {
    String[] photoColumn = new String[]{Media._ID, Media.DATA};
    Cursor coverCursor = cr.query(Media.EXTERNAL_CONTENT_URI, photoColumn, SELECTION_ID,
            new String[]{buckId, "image/jpeg", "image/png", "image/jpg", "image/gif"}, Media.DATE_MODIFIED + " desc");
    try {
        if (coverCursor != null && coverCursor.moveToFirst()) {
            String picPath = coverCursor.getString(coverCursor.getColumnIndex(Media.DATA));
            String id = coverCursor.getString(coverCursor.getColumnIndex(Media._ID));
            album.mCount = coverCursor.getCount();
            album.mImageList.add(new ImageMedia(id, picPath));
            if (album.mImageList.size() > 0) {
                mBucketMap.put(buckId, album);
            }
        }
    } finally {
        if (coverCursor != null) {
            coverCursor.close();
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:AlbumTask.java

示例10: rejectScraperInfos

import android.database.Cursor; //導入方法依賴的package包/類
private void rejectScraperInfos(int position) {
    if (position >= 0) {
        // Get the path corresponding to the item
        Cursor cursor = mActivityFileCursor;
        cursor.moveToPosition(position);
        String path = cursor.getString(mDataIndex);

        // Makie sure this item is processed and that scraper infos have been found
        FileProperties itemProperties = mFileProperties.get(path);
        if (itemProperties.status == ITEM_STATUS_SUCCESS) {
            // Set this item as rejected
            itemProperties.status = ITEM_STATUS_REJECTED;
            Log.d(TAG, "onClick : reject infos for " + path);

            // Reset the scraper fields for this item in the medialib (set them to -1 so
            // that this file will skipped when launching the automated process again)
            // this also removes data from the scraper database
            updateScraperInfoInMediaLib(path, -1, -1);

            // Update the display
            invalidateItem(position);
        }
    }
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:25,代碼來源:AutoScraperActivity.java

示例11: onActivityResult

import android.database.Cursor; //導入方法依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        // When an Image is picked
        if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) {
            // Get the Image from data
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            // Get the cursor
            Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            mTestImgPath = cursor.getString(columnIndex);
            cursor.close();
            if (mTestImgPath != null) {
                runDetectAsync(mTestImgPath);
                //Toast.makeText(this, "Img Path:" + mTestImgPath, Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(this, "You haven't picked Image", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
    }
}
 
開發者ID:gicheonkang,項目名稱:fast_face_android,代碼行數:27,代碼來源:MainActivity.java

示例12: getDataColumn

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } catch (Exception e) {
        return null;
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:37,代碼來源:FileHelper.java

示例13: getDataColumn

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context.
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}
 
開發者ID:garretyoder,項目名稱:Cluttr,代碼行數:33,代碼來源:Util.java

示例14: readEntity

import android.database.Cursor; //導入方法依賴的package包/類
@Override
public TraceUser readEntity(Cursor cursor, int offset) {
    TraceUser entity = new TraceUser( //
        cursor.getString(offset + 0), // login
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
        cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // avatarUrl
        cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // followers
        cursor.isNull(offset + 4) ? null : cursor.getInt(offset + 4), // following
        cursor.isNull(offset + 5) ? null : new java.util.Date(cursor.getLong(offset + 5)), // startTime
        cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)), // latestTime
        cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7) // traceNum
    );
    return entity;
}
 
開發者ID:ThirtyDegreesRay,項目名稱:OpenHub,代碼行數:15,代碼來源:TraceUserDao.java

示例15: setalarm

import android.database.Cursor; //導入方法依賴的package包/類
public void setalarm() {

		if ((!database.isOpen()) || database == null) {
			database = openOrCreateDatabase("db.db", MODE_PRIVATE, null);// 打開數據庫
		}
		int requestCode = 0;
		// ------------------------------獲取數據
		String table = "festival";
		String[] columns = { "name", "date", "flag", "dataid" };
		String selection = null;
		String[] selectionArgs = null;
		Cursor cursor = database.query(table, columns, selection,
				selectionArgs, null, null, null);
		cursor.moveToPosition(cursor.getCount() - 1);// 移動到最後一行
		int idColumnIndex = cursor.getColumnIndex("dataid");
		int idValue = cursor.getInt(idColumnIndex); // 得到最後一行的id
		int contentColumnIndex = cursor.getColumnIndex("name");
		String contentValue = cursor.getString(contentColumnIndex); // 得到最後一行的內容
		int alarmColumnIndex = cursor.getColumnIndex("date");
		String alarmValue = cursor.getString(alarmColumnIndex); // 得到最後一行的鬧鈴時間
		requestCode = idValue;
		// ---------------------------------------------------------------------
		alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
		Intent intent = new Intent(Festival.this, FestivalClockActivity.class);
		intent.putExtra("content", contentValue);// 傳遞內容
		intent.putExtra("alarmtime", alarmValue);// 傳遞鬧鈴時間
		pi = PendingIntent.getActivity(Festival.this, requestCode, intent,
				PendingIntent.FLAG_CANCEL_CURRENT); // 根據id設置不同的鬧鍾
		Calendar alarmTime = Calendar.getInstance();
		long alarmdatetime = changedatetime(alarmValue); // 將時間轉換為long型
		alarmManager.set(AlarmManager.RTC_WAKEUP, alarmdatetime, pi);
		Toast.makeText(getApplicationContext(), "鬧鍾設置好了", Toast.LENGTH_LONG)
				.show();
		database.close();// 關閉數據庫連接
	}
 
開發者ID:z9961,項目名稱:DoList,代碼行數:36,代碼來源:Festival.java


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