android.database.Cursor.getPosition()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(240)

本文整理了Java中android.database.Cursor.getPosition()方法的一些代码示例,展示了Cursor.getPosition()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.getPosition()方法的具体详情如下:
包路径:android.database.Cursor
类名称:Cursor
方法名:getPosition

Cursor.getPosition介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public void bindView(View arg0, Context arg1, Cursor arg2)
{
  int pos = arg2.getPosition();
}

代码示例来源:origin: robolectric/robolectric

@Override @Implementation
public int getPosition() {
 return wrappedCursor.getPosition();
}

代码示例来源:origin: stackoverflow.com

Cursor c = activity.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
int count = c.getCount();
String[] columnNames = c.getColumnNames();
boolean b = c.moveToFirst();
int position = c.getPosition();
if (count == 1 && position == 0) {
  for (int j = 0; j < columnNames.length; j++) {
    String columnName = columnNames[j];
    String columnValue = c.getString(c.getColumnIndex(columnName)));
    ...
    //Use the values
  }
}
c.close();

代码示例来源:origin: stackoverflow.com

Cursor c = activity.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
int count = c.getCount();
String[] columnNames = c.getColumnNames();
boolean b = c.moveToFirst();
int position = c.getPosition();
if (count == 1 && position == 0) {
  for (int j = 0; j < columnNames.length; j++) {
    String columnName = columnNames[j];
    String columnValue = c.getString(c.getColumnIndex(columnName)));
    ...
    // consume the values here
  }
}
c.close();

代码示例来源:origin: facebook/stetho

@Override
public void bindView(View view, Context context, Cursor cursor) {
 ViewHolder holder = (ViewHolder)view.getTag();
 int bindPosition = cursor.getPosition();
 holder.position = bindPosition;
 final String imageUrl = cursor.getString(APODPostsQuery.LARGE_IMAGE_URL_INDEX);
 holder.image.setImageDrawable(null);
 fetchImage(imageUrl, bindPosition, holder);
 cursor.copyStringToBuffer(APODPostsQuery.TITLE_INDEX, holder.titleBuffer);
 setTextWithBuffer(holder.title, holder.titleBuffer);
 cursor.copyStringToBuffer(APODPostsQuery.DESCRIPTION_TEXT_INDEX, holder.descriptionBuffer);
 setTextWithBuffer(holder.description, holder.descriptionBuffer);
}

代码示例来源:origin: naman14/Timber

public static final SortedCursor makeSortedCursor(final Context context, final Cursor cursor,
                         final int idColumn) {
  if (cursor != null && cursor.moveToFirst()) {
    StringBuilder selection = new StringBuilder();
    selection.append(BaseColumns._ID);
    selection.append(" IN (");
    long[] order = new long[cursor.getCount()];
    long id = cursor.getLong(idColumn);
    selection.append(id);
    order[cursor.getPosition()] = id;
    while (cursor.moveToNext()) {
      selection.append(",");
      id = cursor.getLong(idColumn);
      order[cursor.getPosition()] = id;
      selection.append(String.valueOf(id));
    }
    selection.append(")");
    Cursor songCursor = makeSongCursor(context, selection.toString(), null);
    if (songCursor != null) {
      return new SortedCursor(songCursor, order, BaseColumns._ID, null);
    }
  }
  return null;
}

代码示例来源:origin: aa112901/remusic

public static final SortedCursor makeSortedCursor(final Context context, final Cursor cursor,
                         final int idColumn) {
  if (cursor != null && cursor.moveToFirst()) {
    StringBuilder selection = new StringBuilder();
    selection.append(BaseColumns._ID);
    selection.append(" IN (");
    long[] order = new long[cursor.getCount()];
    long id = cursor.getLong(idColumn);
    selection.append(id);
    order[cursor.getPosition()] = id;
    while (cursor.moveToNext()) {
      selection.append(",");
      id = cursor.getLong(idColumn);
      order[cursor.getPosition()] = id;
      selection.append(String.valueOf(id));
    }
    selection.append(")");
    Cursor songCursor = makeSongCursor(context, selection.toString(), null);
    if (songCursor != null) {
      return new SortedCursor(songCursor, order, BaseColumns._ID, null);
    }
  }
  return null;
}

代码示例来源:origin: square/assertj-android

public S hasPosition(int position) {
 isNotNull();
 int actualPosition = actual.getPosition();
 assertThat(actualPosition) //
   .overridingErrorMessage("Expected position <%s> but was <%s>.", position, actualPosition) //
   .isEqualTo(position);
 return myself;
}

代码示例来源:origin: naman14/Timber

mMapCursorPositions.put(mCursor.getLong(idPosition), mCursor.getPosition());
} while (mCursor.moveToNext());

代码示例来源:origin: aa112901/remusic

mMapCursorPositions.put(mCursor.getLong(idPosition), mCursor.getPosition());
} while (mCursor.moveToNext());

代码示例来源:origin: k9mail/k-9

public EmailProviderCacheCursor(String accountUuid, Cursor cursor, Context context) {
  super(cursor);
  mCache = EmailProviderCache.getCache(accountUuid, context);
  mMessageIdColumn = cursor.getColumnIndex(MessageColumns.ID);
  mFolderIdColumn = cursor.getColumnIndex(MessageColumns.FOLDER_ID);
  mThreadRootColumn = cursor.getColumnIndex(ThreadColumns.ROOT);
  if (mMessageIdColumn == -1 || mFolderIdColumn == -1 || mThreadRootColumn == -1) {
    throw new IllegalArgumentException("The supplied cursor needs to contain the " +
        "following columns: " + MessageColumns.ID + ", " + MessageColumns.FOLDER_ID +
        ", " + ThreadColumns.ROOT);
  }
  while (cursor.moveToNext()) {
    long messageId = cursor.getLong(mMessageIdColumn);
    long folderId = cursor.getLong(mFolderIdColumn);
    if (mCache.isMessageHidden(messageId, folderId)) {
      mHiddenRows.add(cursor.getPosition());
    }
  }
  // Reset the cursor position
  cursor.moveToFirst();
  cursor.moveToPrevious();
}

代码示例来源:origin: naman14/Timber

private static void cleanupPlaylist(final Context context, final long playlistId,
                  final Cursor cursor) {
  final int idCol = cursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID);
  final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
  ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
  ops.add(ContentProviderOperation.newDelete(uri).build());
  final int YIELD_FREQUENCY = 100;
  if (cursor.moveToFirst() && cursor.getCount() > 0) {
    do {
      final ContentProviderOperation.Builder builder =
          ContentProviderOperation.newInsert(uri)
              .withValue(Playlists.Members.PLAY_ORDER, cursor.getPosition())
              .withValue(Playlists.Members.AUDIO_ID, cursor.getLong(idCol));
      if ((cursor.getPosition() + 1) % YIELD_FREQUENCY == 0) {
        builder.withYieldAllowed(true);
      }
      ops.add(builder.build());
    } while (cursor.moveToNext());
  }
  try {
    context.getContentResolver().applyBatch(MediaStore.AUTHORITY, ops);
  } catch (RemoteException e) {
  } catch (OperationApplicationException e) {
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetPosition() throws Exception {
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(0);
 assertThat(cursor.moveToNext()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(1);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testMoveBackwards() throws Exception {
 assertThat(cursor.getPosition()).isEqualTo(-1);
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(0);
 assertThat(cursor.moveToNext()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(1);
 assertThat(cursor.moveToNext()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(2);
 assertThat(cursor.moveToFirst()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(0);
 assertThat(cursor.moveToNext()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(1);
 assertThat(cursor.moveToNext()).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(2);
 assertThat(cursor.moveToPosition(1)).isTrue();
 assertThat(cursor.getPosition()).isEqualTo(1);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldAlwaysReturnCorrectIdFromInsert() throws Exception {
  database.execSQL("CREATE TABLE table_A (\n" +
      "  _id INTEGER PRIMARY KEY AUTOINCREMENT,\n" +
      "  id INTEGER DEFAULT 0\n" +
      ");");
  database.execSQL("CREATE VIRTUAL TABLE new_search USING fts3 (id);");
  database.execSQL("CREATE TRIGGER t1 AFTER INSERT ON table_A WHEN new.id=0 BEGIN UPDATE table_A SET id=-new._id WHERE _id=new._id AND id=0; END;");
  database.execSQL("CREATE TRIGGER t2 AFTER INSERT ON table_A BEGIN INSERT INTO new_search (id) VALUES (new._id); END;");
  database.execSQL("CREATE TRIGGER t3 BEFORE UPDATE ON table_A BEGIN DELETE FROM new_search WHERE id MATCH old._id; END;");
  database.execSQL("CREATE TRIGGER t4 AFTER UPDATE ON table_A BEGIN INSERT INTO new_search (id) VALUES (new._id); END;");
  long[] returnedIds = new long[]{
      database.insert("table_A", "id", new ContentValues()),
      database.insert("table_A", "id", new ContentValues())
  };
  Cursor c = database.query("table_A", new String[]{"_id"}, null, null, null, null, null);
  assertThat(c).isNotNull();
  long[] actualIds = new long[c.getCount()];
  for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
    actualIds[c.getPosition()] = c.getLong(c.getColumnIndexOrThrow("_id"));
  }
  c.close();
  assertThat(returnedIds).isEqualTo(actualIds);
}

代码示例来源:origin: k9mail/k-9

holder.flagged.setChecked(flagged);
holder.position = cursor.getPosition();
if (holder.contactBadge != null) {
  updateContactBadge(holder, counterpartyAddress);

代码示例来源:origin: parse-community/Parse-SDK-Android

@Override
public int getPosition() {
  return cursor.getPosition();
}

代码示例来源:origin: stackoverflow.com

@Override
public void bindView(View view, Context context, final Cursor cursor) {
 // TODO Auto-generated method stub
  TextView tv1 = (TextView)view.findViewById(R.id.txt_name);
  TextView tv2 = (TextView)view.findViewById(R.id.txt_numer);

  tv1.setText(cursor.getString(2));
  tv2.setText(cursor.getString(3));

  final Button call_btn= (Button)view.findViewById(R.id.call_btn);    
  final int position = cursor.getPosition();

  call_btn.setOnClickListener(new Button.OnClickListener(){

    @Override
    public void onClick(View v) { 

      cursor.moveToPosition(position);
      Toast.makeText(b, cursor.getString(1), Toast.LENGTH_SHORT).show();

    }}); 

 }

代码示例来源:origin: DaxiaK/MyDiary

public void showCursor(Cursor cursor) {
  for (int i = 0; i < cursor.getCount(); i++) {
    StringBuilder sb = new StringBuilder();
    int columnsQty = cursor.getColumnCount();
    for (int idx = 0; idx < columnsQty; ++idx) {
      sb.append(" " + idx + " = ");
      sb.append(cursor.getString(idx));
      if (idx < columnsQty - 1)
        sb.append(" ; ");
    }
    Log.e("test", String.format("Row: %d, Values: %s", cursor.getPosition(), sb.toString()));
    cursor.moveToNext();
  }
  //Revert Cursor
  cursor.moveToFirst();
}

代码示例来源:origin: stackoverflow.com

RingtoneManager ringtoneMgr = new RingtoneManager(this);
ringtoneMgr.setType(RingtoneManager.TYPE_ALARM);
Cursor alarmsCursor = ringtoneMgr.getCursor();
int alarmsCount = alarmsCursor.getCount();
if (alarmsCount == 0 && !alarmsCursor.moveToFirst()) {
  return null;
}
Uri[] alarms = new Uri[alarmsCount];
while(!alarmsCursor.isAfterLast() && alarmsCursor.moveToNext()) {
  int currentPosition = alarmsCursor.getPosition();
  alarms[currentPosition] = ringtoneMgr.getRingtoneUri(currentPosition);
}
alarmsCursor.close();
return alarms;

相关文章