本文整理匯總了Java中android.database.Cursor.moveToLast方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.moveToLast方法的具體用法?Java Cursor.moveToLast怎麽用?Java Cursor.moveToLast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.database.Cursor
的用法示例。
在下文中一共展示了Cursor.moveToLast方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkForDuplicateImage
import android.database.Cursor; //導入方法依賴的package包/類
/**
* Used to find out if we are in a situation where the Camera Intent adds to images
* to the content store. If we are using a FILE_URI and the number of images in the DB
* increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
*
* @param type FILE_URI or DATA_URL
*/
private void checkForDuplicateImage(int type) {
int diff = 1;
Uri contentStore = whichContentStore();
Cursor cursor = queryImgDB(contentStore);
int currentNumOfImages = cursor.getCount();
if (type == FILE_URI && this.saveToPhotoAlbum) {
diff = 2;
}
// delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
if ((currentNumOfImages - numPics) == diff) {
cursor.moveToLast();
int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
if (diff == 2) {
id--;
}
Uri uri = Uri.parse(contentStore + "/" + id);
this.cordova.getActivity().getContentResolver().delete(uri, null, null);
cursor.close();
}
}
示例2: getAllTasks
import android.database.Cursor; //導入方法依賴的package包/類
public List<TasksManagerModel> getAllTasks() {
final Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
final List<TasksManagerModel> list = new ArrayList<>();
try {
if (!c.moveToLast()) {
return list;
}
do {
TasksManagerModel model = new TasksManagerModel();
model.setId(c.getInt(c.getColumnIndex(TasksManagerModel.ID)));
model.setName(c.getString(c.getColumnIndex(TasksManagerModel.NAME)));
model.setUrl(c.getString(c.getColumnIndex(TasksManagerModel.URL)));
model.setPath(c.getString(c.getColumnIndex(TasksManagerModel.PATH)));
list.add(model);
} while (c.moveToPrevious());
} finally {
if (c != null) {
c.close();
}
}
return list;
}
示例3: getPageHezb
import android.database.Cursor; //導入方法依賴的package包/類
public int getPageHezb(int pageNumber) {
int hezbNumber = 0;
try {
SQLiteDatabase db = openDB(MAIN_DATABASE);
String sql = "select hezb from aya where page = " + pageNumber + " ;";
Cursor cursor = db.rawQuery(sql, null);
if(cursor.moveToLast()){
hezbNumber = cursor.getInt(0);
}
cursor.close();
closeDB(db);
return hezbNumber;
} catch (Exception e) {
e.printStackTrace();
}
return hezbNumber;
}
示例4: onChange
import android.database.Cursor; //導入方法依賴的package包/類
@Override public void onChange(boolean selfChange, Uri uri) {
ArrayList<String> phoneNumber = new ArrayList<>();
super.onChange(selfChange, uri);
Log.d(LOG_TAG, "Contact has changed");
Cursor cursor = getReactApplicationContext().getContentResolver()
.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (!cursor.moveToFirst()) return;
cursor.moveToLast();
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String phone =
cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.d(LOG_TAG, "id = " + name + "\n name = " + name);
phoneNumber.add(phone);
synchronizePhoneNumber(phoneNumber);
}
示例5: getLastMessage
import android.database.Cursor; //導入方法依賴的package包/類
public Message getLastMessage(int roomID) throws Exception {
String roomIDString = getRoomIdString(roomID);
String query = "SELECT * FROM "+roomIDString+" ORDER BY "+ROOM_TIMESTAMP+" ASC";
SQLiteDatabase db = getWritableDatabase();
Cursor c = db.rawQuery(query, null);
c.moveToLast();
int messageID = c.getInt(c.getColumnIndex(ROOM_MESSAGEID));
String name = c.getString(c.getColumnIndex(ROOM_SENDER));
String text = c.getString(c.getColumnIndex(ROOM_TEXT));
long timestamp = c.getLong(c.getColumnIndex(ROOM_TIMESTAMP));
Message message = new Message(messageID, roomID, name, text, timestamp);
c.close();
db.close();
return message;
}
示例6: getLastAlarm
import android.database.Cursor; //導入方法依賴的package包/類
public AlarmResponse getLastAlarm(int versionCode) {
String whereClause = "targetVersion = " + versionCode;
Cursor cursor = null;
try {
cursor = this.openHelper.getReadableDatabase().query(DBConstants.TABLE_ALARM, null, whereClause, null, null, null, DBConstants.ID);
if (!cursor.moveToLast()) {
return null;
}
AlarmResponse alarmFromCursor = getAlarmFromCursor(cursor);
if (cursor == null) {
return alarmFromCursor;
}
cursor.close();
return alarmFromCursor;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例7: getLastRoad
import android.database.Cursor; //導入方法依賴的package包/類
public RoadModel getLastRoad(long folderId) {
Cursor c = getAllRoadByFolderIdCursor(folderId);
RoadModel road = null;
try {
if (c != null) {
if (c.getCount() > 0) {
c.moveToLast();
road = cursorToRoad(c);
}
c.close();
}
} catch (Exception e) {
Log.e(TAG, e != null && e.getMessage() != null ? e.getMessage() : "");
}
return road;
}
示例8: getDisableApps
import android.database.Cursor; //導入方法依賴的package包/類
/**
* 獲取主頁停用列表apps
*
* @param tableName
* @return
*/
public List<AppInfo> getDisableApps(String tableName) {
final Cursor cursor = mSQLiteDatabase.rawQuery("SELECT * FROM " + tableName, null);
final List<AppInfo> list = new ArrayList<>();
try {
if (!cursor.moveToLast()) {
return list;
}
do {
AppInfo appInfo = new AppInfo();
appInfo.setAppPackageName(cursor.getString(cursor.getColumnIndex(AppInfo.APP_PACKAGE_NAME)));
appInfo.setAppName(cursor.getString(cursor.getColumnIndex(AppInfo.APP_NAME)));
MyLogger.e(cursor.getString(cursor.getColumnIndex(AppInfo.APP_NAME)));
appInfo.setAppIcon(CommonUtil.getImage(cursor.getBlob(cursor.getColumnIndex(AppInfo.APP_ICON))));
appInfo.setEnable(cursor.getInt(cursor.getColumnIndex(AppInfo.IS_ENABLE)));
appInfo.setSystemApp(cursor.getInt(cursor.getColumnIndex(AppInfo.IS_SYSTEM_APP)));
list.add(appInfo);
} while (cursor.moveToPrevious());
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return list;
}
示例9: getUrlDataFromDB
import android.database.Cursor; //導入方法依賴的package包/類
private String getUrlDataFromDB() {
Cursor cursor = mSQLiteDataBase.rawQuery("SELECT url_data FROM my_url_data", null);
cursor.moveToLast();
String a = cursor.getString(cursor.getColumnIndex("url_data"));
// String s = cursor.getString(2);
return a;
}
示例10: findLastValue
import android.database.Cursor; //導入方法依賴的package包/類
protected static int findLastValue(DBHandler db, String tableName){
int foundValue;
String selectQuery = "SELECT * FROM " + tableName;
SQLiteDatabase db1 = db.getReadableDatabase();
Cursor cursor = db1.rawQuery(selectQuery, null);
cursor.moveToLast();
foundValue = Integer.parseInt(cursor.getString(1));
cursor.close();
return foundValue;
}
示例11: gewaehlteFaecherAnTag
import android.database.Cursor; //導入方法依賴的package包/類
public Fach[] gewaehlteFaecherAnTag(int tag) {
String table = TABLE_FAECHER + ", " + TABLE_GEWAEHLT + ", " + TABLE_STUNDEN;
String[] columns = {TABLE_FAECHER + "." + FACH_ID,
FACH_KURZEL,
FACH_NAME,
FACH_ART,
FACH_LEHRER,
FACH_KLASSE,
STUNDE_RAUM,
STUNDEN_STUNDE,
GEWAEHLT_SCHRIFTLICH,
STUNDE_NOTIZ};
String selection = TABLE_FAECHER + "." + FACH_ID + " = " + TABLE_STUNDEN + "." + FACH_ID + " AND " + TABLE_FAECHER + "." + FACH_ID + " = " + TABLE_GEWAEHLT + "." + FACH_ID + " AND " + TABLE_STUNDEN + "." + STUNDEN_TAG + " = " + tag;
Cursor cursor = database.query(table, columns, selection, null, null, null, STUNDEN_STUNDE);
Fach[] faecher = new Fach[0];
if (cursor.getCount() > 0) {
cursor.moveToLast();
faecher = new Fach[cursor.getInt(7)];
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
faecher[cursor.getInt(7) - 1] = new Fach(cursor.getInt(0), cursor.getString(1), cursor.getString(2) + (cursor.getString(3).equals("LK") ? " LK" : ""), cursor.getString(4), cursor.getString(5), cursor.getString(6), tag, cursor.getInt(7));
faecher[cursor.getInt(7) - 1].setzeNotiz(cursor.getString(9));
faecher[cursor.getInt(7) - 1].setzeSchriftlich(cursor.getInt(8) == 1);
}
for (int i = 0; i < faecher.length; i++) {
if (faecher[i] == null)
faecher[i] = new Fach(0, "", "", "", "", "", tag, i + 1);
}
}
cursor.close();
return faecher;
}
示例12: getLastItemId
import android.database.Cursor; //導入方法依賴的package包/類
private int getLastItemId(Integer databaseKey) {
open();
String sql = "SELECT " + SearchHistoryDatabase.SEARCH_HISTORY_COLUMN_ID + " FROM " + SearchHistoryDatabase.SEARCH_HISTORY_TABLE;
if (databaseKey != null)
sql += " WHERE " + SearchHistoryDatabase.SEARCH_HISTORY_KEY + " = " + databaseKey;
Cursor res = db.rawQuery(sql, null);
res.moveToLast();
int count = res.getInt(0);
close();
res.close();
return count;
}
示例13: aggregateEvents
import android.database.Cursor; //導入方法依賴的package包/類
/**
* Iterates sqlite cursor and builds complete GameHarvest objects
*
* @param cursor sqlite cursor
* @param getDeletedImages
* @return List of GameHarvest objects
*/
private List<GameHarvest> aggregateEvents(Cursor cursor, boolean getDeletedImages) {
cursor.moveToFirst();
List<LogImage> logImages = new ArrayList<LogImage>();
boolean first = true;
int lastId = 0;
List<GameHarvest> logEvents = new ArrayList<GameHarvest>();
while (!cursor.isAfterLast()) {
int eventId = cursor.getInt(cursor.getColumnIndex(DiaryHelper.COLUMN_LOCALID));
if (!first && eventId != lastId) {
cursor.moveToPrevious();
logEvents.add(createEvent(cursor, logImages));
logImages = new ArrayList<LogImage>();
cursor.moveToNext();
}
LogImage image = logImageFromCursor(cursor, getDeletedImages);
if (image != null)
logImages.add(image);
lastId = eventId;
cursor.moveToNext();
first = false;
}
if (cursor.getCount() > 0) {
cursor.moveToLast();
logEvents.add(createEvent(cursor, logImages));
}
return logEvents;
}
示例14: getMessages
import android.database.Cursor; //導入方法依賴的package包/類
private List<HashMap<String,String>> getMessages(String where, String[] whereArgs, int limitStart, int limitEnd){
Uri uri = Uri.parse("content://sms");
Cursor c = mContext.getContentResolver().query(uri,
null,
where,
whereArgs,
"date desc LIMIT "+String.valueOf(limitStart)+", "+String.valueOf(limitEnd)
);
List<HashMap<String,String>> ret = new ArrayList<HashMap<String, String>>();
if (c.getCount() > 0){
c.moveToLast();
for (int i = 0; i < c.getCount(); i++) {
String msgId = c.getString(c.getColumnIndex("_id"));
String address = c.getString(c.getColumnIndex("address")); // phone #
String date = c.getString(c.getColumnIndex("date"));
String body = c.getString(c.getColumnIndex("body"));
//String seen = c.getString(c.getColumnIndex("read"));
String type = c.getString(c.getColumnIndex("type"));
int thread = c.getInt(c.getColumnIndexOrThrow("thread_id"));
ContactsUtil mContacts = new ContactsUtil(mContext);
String contactId = mContacts.getContactId(address);
String name = address;
if (!(contactId == null)) {
HashMap<String, String> contact = mContacts.getContactById(Integer.parseInt(contactId));
name = contact.get("name");
}
HashMap<String,String> currMsg = new HashMap<>();
currMsg.put("address",address);
currMsg.put("name",name);
currMsg.put("date",date); //timestamp
currMsg.put("content",body);
currMsg.put("contact_id",contactId);
currMsg.put("type",type);
currMsg.put("msg_id", msgId);
currMsg.put("thread_id", String.valueOf(thread));
ret.add(currMsg);
c.moveToPrevious();
}
}
return ret;
}
示例15: onActivityResult
import android.database.Cursor; //導入方法依賴的package包/類
protected void onActivityResult (int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
ContentResolver reContentResolverol = getContentResolver();
Uri contactData = data.getData();
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(contactData, null, null, null, null);
cursor.moveToFirst();
name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
Cursor phone = reContentResolverol.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
null,
null);
while (phone.moveToNext()) {
number = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
isfrist=false;
//add a contact
db.open();
long id = db.insertContact(name, number);
if(isfrist !=true)
{
//get a contact
db.open();
Cursor a = db.getContact(id);
if (a.moveToLast()){
Map<String, Object> map = new HashMap<String, Object>();
map.put("contacts_name", name);
map.put("contacts_num", number);
dataList.add(map);
simpleadapter = new SimpleAdapter(this, dataList, R.layout.contact_text, new String[]{"contacts_name","contacts_num"},
new int[]{R.id.contacts_name,R.id.contacts_num});
listView.setAdapter(simpleadapter);
simpleadapter.notifyDataSetChanged();
// DisplayContact(a);
}
else
Toast.makeText(this, "No contact found!", Toast.LENGTH_SHORT).show();
}
db.close();
}
}