本文整理汇总了Java中android.database.Cursor.moveToFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.moveToFirst方法的具体用法?Java Cursor.moveToFirst怎么用?Java Cursor.moveToFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.Cursor
的用法示例。
在下文中一共展示了Cursor.moveToFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onContactRetrieved
import android.database.Cursor; //导入方法依赖的package包/类
@Override
public void onContactRetrieved(Cursor contactInfoCursor) {
contactInfoCursor.moveToFirst();
try {
final String displayName = contactInfoCursor.getString(contactInfoCursor.getColumnIndex
(ContactsContract.Contacts.DISPLAY_NAME));
final String phoneNumber = contactInfoCursor.getString(contactInfoCursor.getColumnIndex
(ContactsContract.CommonDataKinds.Phone.NUMBER)).replaceAll("[-() ]", "");
Prefs.with((DetentionAlertActivity) detentionAlertView).write(
PreferencesUtils.PREFERENCES_SELECTED_CONTACT_NAME, displayName
);
Prefs.with((DetentionAlertActivity) detentionAlertView).write(
PreferencesUtils.PREFERENCES_SELECTED_CONTACT_NUMBER, phoneNumber
);
detentionAlertView.contactSelected(displayName);
} catch (Exception e) {
e.printStackTrace();
detentionAlertView.contactError();
} finally {
contactInfoCursor.close();
}
}
示例2: getCoverArtPath
import android.database.Cursor; //导入方法依赖的package包/类
private static String getCoverArtPath(long albumId, Context context) {
Cursor albumCursor = context.getContentResolver().query(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID + " = ?",
new String[]{Long.toString(albumId)},
null
);
boolean queryResult = albumCursor.moveToFirst();
String result = null;
if (queryResult) {
result = albumCursor.getString(0);
}
albumCursor.close();
return result;
}
示例3: loadProvinces
import android.database.Cursor; //导入方法依赖的package包/类
public List<Province> loadProvinces() {
List<Province> provinceList = new ArrayList<>();
Cursor cursor = db.query("province", null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Province province = new Province();
province.setId(cursor.getInt(cursor.getColumnIndex("id")));
province.setProvinceName(cursor.getString(cursor.getColumnIndex("province_name")));
province.setProvinceCode(cursor.getString(cursor.getColumnIndex("province_code")));
provinceList.add(province);
} while (cursor.moveToNext());
}
if (cursor != null) {
cursor.close();
}
return provinceList;
}
示例4: 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;
}
示例5: gethomedata
import android.database.Cursor; //导入方法依赖的package包/类
public List gethomedata() {
Log.d("TAGGGGG", "insideeeeeee gethomedata");
List<HomePostsModel> homedetails = new ArrayList<>();
String query = "select * from " + TABLE_HOMEPOST;
SQLiteDatabase db = getReadableDatabase();
mdb = getReadableDatabase();
Cursor cursor = db.rawQuery(query, null);
Log.d("LOG", "cursorr" + cursor.toString());
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
do {
HomePostsModel homeposts = new HomePostsModel();
String id = cursor.getString(cursor.getColumnIndex(NOTIFICATION_ID));
String title = cursor.getString(cursor.getColumnIndex(NOTIFICATION_TITLE));
String small_icon = cursor.getString(cursor.getColumnIndex(NOTIFICATION_small_icon));
Log.d("TAG", "valuesss" +id+title+small_icon);
homeposts.setNotification_id(id);
homeposts.setTitle(title);
homeposts.setSmall_icon(small_icon);
homedetails.add(homeposts);
} while (cursor.moveToNext());
for (int i = 0; i < homedetails.size(); i++) {
Log.d("LOG", "arrryyyy" + homedetails.get(i).toString());
}
cursor.close();
}
} catch (Exception e) {
Log.d("TAG", "Error while trying to get posts from database");
}
} else {
Log.d("DB", "cursor emptyyyy");
}
return homedetails;
}
示例6: getPath
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Función que obtiene el path de un bitmap para cargarlo en el imageView.
*
* @param uri
* @param activity
* @return
*/
public String getPath(Uri uri, Activity activity) {
String[] projection = {MediaStore.MediaColumns.DATA};
Cursor cursor = activity
.managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
示例7: count
import android.database.Cursor; //导入方法依赖的package包/类
public int count() {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("select * from contacts", null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
return cursor.getInt(0);
} else {
return 0;
}
}
示例8: querySumByTaskId
import android.database.Cursor; //导入方法依赖的package包/类
public long querySumByTaskId(long taskId) {
SQLiteDatabase db = RecordManager.openDatabase();
String sql = "select sum("+SqlConst.TB_THREAD_FINISHED+") from "+ TABLE_NAME +" where "+SqlConst.TB_TASK_ID+"=?";
String[] whereArgs = {String.valueOf(taskId)};
Cursor cursor = db.rawQuery(sql,whereArgs);
SubTaskRecord record = null;
long sum = 0;
if (cursor.moveToFirst()) {
sum = cursor.getLong(0);
}
cursor.close();
return sum;
}
示例9: getAll
import android.database.Cursor; //导入方法依赖的package包/类
public List<DBBlock> getAll() {
List<DBBlock> dbblocks = new ArrayList<DBBlock>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_BLOCKSTORE, allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
dbblocks.add(cursorToBlock(cursor));
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return dbblocks;
}
示例10: getPartStartPage
import android.database.Cursor; //导入方法依赖的package包/类
/**
* Function to get the part start page
*
* @param partNumber Part Number
* @return Page number
*/
public int getPartStartPage(int partNumber) {
int pageNumber = 0;
SQLiteDatabase db = openDB(MAIN_DATABASE);
String sql = "select page from aya where joza = " + partNumber + " limit 1 ;";
Cursor cursor = db.rawQuery(sql, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
pageNumber = cursor.getInt(0);
cursor.moveToNext();
}
cursor.close();
closeDB(db);
return pageNumber;
}
示例11: getCount
import android.database.Cursor; //导入方法依赖的package包/类
public Long getCount(){
String sql = "select count(*) from "+Task.TABLE;
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
cursor.moveToFirst();
long count = cursor.getLong(0);
cursor.close();
return count;
}
示例12: getAllCookies
import android.database.Cursor; //导入方法依赖的package包/类
public List<Cookie> getAllCookies() {
List<Cookie> cookies = new ArrayList<Cookie>();
Cursor cursor = db
.query(TABLE_NAME, null, null, null, null, null, null);
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(Column.NAME));
String value = cursor
.getString(cursor.getColumnIndex(Column.VALUE));
BasicClientCookie cookie = new BasicClientCookie(name, value);
cookie.setComment(cursor.getString(cursor
.getColumnIndex(Column.COMMENT)));
cookie.setDomain(cursor.getString(cursor
.getColumnIndex(Column.DOMAIN)));
long expireTime = cursor.getLong(cursor
.getColumnIndex(Column.EXPIRY_DATE));
if (expireTime != 0) {
cookie.setExpiryDate(new Date(expireTime));
}
cookie.setPath(cursor.getString(cursor.getColumnIndex(Column.PATH)));
cookie.setSecure(cursor.getInt(cursor.getColumnIndex(Column.SECURE)) == 1);
cookie.setVersion(cursor.getInt(cursor
.getColumnIndex(Column.VERSION)));
cookies.add(cookie);
}
cursor.close();
return cookies;
}
示例13: getWifiServer
import android.database.Cursor; //导入方法依赖的package包/类
public WifiServer getWifiServer(long id){
SQLiteDatabase db = this.getReadableDatabase();
WifiServer wifiServer = new WifiServer();
wifiServer.setId(id);
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE_SERVERS +
" JOIN " + TABLE_WIFI_SERVERS +
" USING(" + COLUMN_ID + ")");
Cursor c = qb.query(db,
new String[]{COLUMN_IS_ENABLED,
COLUMN_CERTIFICATE_ID,
COLUMN_IP_OR_HOSTNAME,
COLUMN_PORT_NUMBER,
COLUMN_SSID_WHITELIST},
COLUMN_ID + "=?", new String[]{String.valueOf(id)},
null, null, null);
if (c.moveToFirst()){
wifiServer.setIsEnabled(intToBool(c.getInt(0)));
wifiServer.setCertificateId(c.getLong(1));
wifiServer.setIpOrHostname(c.getString(2));
wifiServer.setPortNumber(c.getInt(3));
wifiServer.setSsidWhitelist(c.getString(4));
}
c.close();
db.close();
return wifiServer;
}
示例14: setSelectedCar
import android.database.Cursor; //导入方法依赖的package包/类
private void setSelectedCar(long id, boolean needCallRun) {
SharedPreferences.Editor editor = mPreferences.edit();
editor.putLong(AndiCar.getAppResources().getString(R.string.pref_key_last_selected_car_id), id);
editor.apply();
mLastSelectedCarID = id;
//get the car details
String columnsToGet[] = {DBAdapter.COL_NAME_GEN_ROWID, DBAdapter.COL_NAME_GEN_NAME, DBAdapter.COL_NAME_GEN_USER_COMMENT,
DBAdapter.COL_NAME_CAR__REGISTRATIONNO, DBAdapter.COL_NAME_CAR__INDEXCURRENT};
String selectionCondition = DBAdapter.COL_NAME_GEN_ROWID + "=?";
String[] selectionArgs = {String.valueOf(id)};
DBAdapter db = new DBAdapter(this);
Cursor c = db.query(DBAdapter.TABLE_NAME_CAR, columnsToGet, selectionCondition, selectionArgs, DBAdapter.COL_NAME_GEN_NAME);
if (c.moveToFirst()) {
mNavigationView.setHeaderLabels(c.getString(1), c.getString(3), c.getString(2));
setTitle(c.getString(1) + " - " +
Utils.numberToString(c.getDouble(4), true, 0, RoundingMode.HALF_UP) + " " + db.getUOMCode(db.getCarUOMLengthID(c.getLong(0))));
}
else {
mNavigationView.setHeaderLabels(getString(R.string.main_activity_no_car_title), "", "");
setTitle(getString(R.string.main_activity_no_car_title));
}
c.close();
mIsAlternateFuelVehicle = db.isAFVCar(mLastSelectedCarID);
db.close();
if (needCallRun) {
fillContent();
}
}
示例15: getCityInfo
import android.database.Cursor; //导入方法依赖的package包/类
private City getCityInfo(String city) {
Cursor c = db.rawQuery("SELECT * from " + CITY_TABLE_NAME
+ " where city=?", new String[]{city});
if (c.moveToFirst()) {
String province = c.getString(c.getColumnIndex("province"));
String name = c.getString(c.getColumnIndex("city"));
Double latitude = c.getDouble(c.getColumnIndex("latitude"));
Double longitude = c.getDouble(c.getColumnIndex("longitude"));
City item = new City(province, name, latitude, longitude);
return item;
}
return null;
}