我有1个Activity和1个片段,它们具有以下代码
活动1
Database createConn(Database database) {
try {
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
database = manager.getDatabase("couchbaseevents");
} catch (Exception e) {
android.util.Log.d(TAG, "Error getting database", e);
return database;
}
return database;
}
private com.couchbase.lite.View createView(Database database){
com.couchbase.lite.View calendarView = database.getView("calendar");
calendarView.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
{
emitter.emit(document.get("date"),document.get("cost"));
}
}
},"2");
return calendarView;
}
Database database = createConn(database);
calendarView = createView(database);
片段1
Database createConn(Database database) {
try {
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
database = manager.getDatabase("couchbaseevents");
} catch (Exception e) {
android.util.Log.d(TAG, "Error getting database", e);
return database;
}
return database;
}
Database database = createConn(database);
Query query = database.getView("calendar").createQuery();
当我在片段中对CBL运行查询时,我得到空结果但是如果我在片段中创建View
而不是在活动中我得到了期望的结果,但我不想那样。我希望该视图应该在activity中创建并在片段中调用。这可能吗?如果是,那么请举例。