Skip to content

Instantly share code, notes, and snippets.

@thuytrinh
Created November 22, 2014 04:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuytrinh/0cec49eabac5b7f13f78 to your computer and use it in GitHub Desktop.
Save thuytrinh/0cec49eabac5b7f13f78 to your computer and use it in GitHub Desktop.
import android.database.Cursor;
import java.util.Iterator;
public class IterableCursor implements Iterable<Cursor> {
private Cursor cursor;
public IterableCursor(Cursor cursor) {
this.cursor = cursor;
this.cursor.moveToPosition(-1);
}
@Override
public Iterator<Cursor> iterator() {
return new Iterator<Cursor>() {
@Override
public boolean hasNext() {
return !cursor.isClosed() && cursor.moveToNext();
}
@Override
public Cursor next() {
return cursor;
}
@Override
public void remove() {}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment