【发布时间】:2016-08-07 07:28:46
【问题描述】:
我想从我的 android 项目中的领域数据库中获取 20 条记录,然后获取接下来的 20 条记录并在每个步骤中获取其他记录,直到从领域获取我的所有记录。
这是我的领域数据库功能,用于获取许多特殊记录
public ArrayList<Post> loadLikedPost() {
ArrayList<Post> posts_database = new ArrayList<Post>();
realm.beginTransaction();
ListIterator<PostDatabase> posts;
posts = realm.where(PostDatabase.class).equalTo("is_like", true).findAll().sort("post_id", Sort.DESCENDING).listIterator();
int size = realm.where(PostDatabase.class).equalTo("is_like", true).findAll().size();
realm.commitTransaction();
int i = 0;
while(posts.hasNext() && i < 20) {
PostDatabase pd = posts.next();
Post p = new Post();
p.text = pd.getText();
p.img = pd.getImg();
p.post_id = pd.getPost_id();
p.width = pd.getWidth();
p.height = pd.getHeight();
p.date = pd.getDate();
p.is_visible = pd.getIs_visible();
p.likes = pd.getLikes();
p.is_like = pd.getIs_like();
p.entity = new ArrayList<Entity>();
for(EntityDatabase ed : pd.getEntity()) {
Entity e = new Entity();
e.length = ed.getLenght();
e.offset = ed.getOffset();
e.type = ed.getType();
p.entity.add(e);
}
p.setSpan();
p.setImg(context);
posts_database.add(p);
i++;
}
Collections.reverse(posts_database);
return posts_database;
}
这是我的函数,用于加载我从上一个函数中获得的记录
public void loadPost() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
callDatabase = new CallDatabase(context);
callDatabase = new CallDatabase(context);
callListener.onGetLikedPosts(PostController.getVisiblePosts(callDatabase.loadLikedPost(i), true));
}
});
thread.start();
}
现在我只能获取前 20 条记录,我该怎么办?
提前致谢。
【问题讨论】:
-
没有更多信息,这很难说。请发布您现在使用的代码。
-
@SaraGorzin 在伊朗使用 Realm.io 违反了LICENSE:
You understand that the Software may contain cryptographic functions that may be subject to export restrictions, and you represent and warrant that you are not located in a country that is subject to United States export restriction or embargo, including Cuba, Iran, North Korea, Sudan, Syria or the Crimea region, and that you are not on the Department of Commerce list of Denied Persons, Unverified Parties, or affiliated with a Restricted Entity.