本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
}
示例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;
}
示例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();
}
}
}
示例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);
}
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();// 关闭数据库连接
}