我需要存储他自己异步的FireBase getValue方法的结果.我不能使用类似"onPostExecute()"的东西,为了我的目的,我无法执行"onDataChange()"的所有操作,因为我需要在将来的其他活动中引用一些参考.
这是我的片段检索数据:
List<Village> villages = new LinkedList<>();
Firebase ref = new Firebase("MYFIREBASEURL").child("village");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
spinnerArray.clear();
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Village v = postSnapshot.getValue(Village.class);
villages.add(v);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
Run Code Online (Sandbox Code Playgroud)
如果我尝试从"onDataChange"中读取村庄,我自然会为他的异步生活读取空值.有一种方法可以确保调用onDataChange吗?
android synchronization asynchronous firebase firebase-realtime-database
我希望标题清楚.我想隐藏一个元素(在我的情况下是数据选择器),我也想隐藏他的空间.所以我用动画尝试了这个:
@IBAction func showQnt(sender: AnyObject) {
if (self.pickerQnt.alpha == 0.0){
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.ShowHideTransitionViews, animations: {
self.pickerQnt.alpha = 1.0
}, completion: {
(finished: Bool) -> Void in
//var constH = NSLayoutConstraint(item: self.pickerQnt, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 162)
//self.pickerQnt.addConstraint(constH)
})
} else {
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.ShowHideTransitionViews, animations: {
self.pickerQnt.alpha = 0.0
}, completion: {
(finished: Bool) -> Void in
// CHECK: ?!? constrain to set view height to 0 run time …Run Code Online (Sandbox Code Playgroud) @IBAction func selectedGame(segue:UIStoryboardSegue) {
if let gamePickerViewController = segue.sourceViewController as? GamePickerViewController,
selectedGame = gamePickerViewController.selectedGame {
detailLabel.text = selectedGame
game = selectedGame
}
}
Run Code Online (Sandbox Code Playgroud)
大家好,我正在学习一些关于swift的教程.昨天我发现了这部分代码,但我找不到理解这意味着什么意思的方法.你可以解释一下吗?