我看到很多帖子让doThing()
延迟了每个事件的发布:How to make countdown timer with RxJS Observables?,How to use RxJava Interval Operator,Adding delay between Observable Items RxJava,RxJava delay for each item of list emitted和其他
尽管如此,我没有看到任何链接有不同的延迟。
基本上,我有一个Textview和一个字母列表,我想:
代码实现可能看起来像这样(但我认为Rx
中的delay()
是无意义的,Observable.fromArray(new String[]{"A", "B", "C", "D", "E"})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.delay(500L, TimeUnit.MILLISECONDS)
.doThing((String i) -> {
textView.setText("");
Log.d("XXX", "MainActivity :: onCreate (110): letter="+ i);
})
.delay(1500L, TimeUnit.MILLISECONDS)
.doThing((String i) -> {
textView.setText(i);
Log.d("XXX", "MainActivity :: onCreate (110): letter="+ i);
});
不适用于此:)
$("#cbox2").click(function(){
var jsonlink = $('#jsonlink').val();
var jsonkey = $('#jsonkey').val(); //The input KEY
$.ajax({
type: "GET",
url: jsonlink,
dataType: 'json',
cache: false,
success: function(data) {
data.forEach(function(post) {
var jsondakey = post[jsonkey]; //Where the key is used to get the correct data
$('#listacroche').append( '<div class="row"><div class="col s5"><input name="foo" value="' + jsondakey + '" type="checkbox" id="checkgrp' + jsondakey + '" /><label for="checkgrp' + jsondakey + '">' + jsondakey + '</label></div></div>' );
});
},
complete: function() {
console.log("List des groupes avec succès");
}
});
});
如何使用Rx实现这一目标?
编辑:我可以使用rxjava delay: How to get variable delay on each item emitted from a list?的答案,其中包含一个字母列表,其中一个字母对两个字母是特殊的(可能是null?),但它看起来过于复杂。
答案 0 :(得分:1)
Sequence: JScrollPane
private JPanel imagesPanel() {
JPanel panel = new JPanel(new GridBagLayout());
int x = 0;
int y = 0;
GridBagConstraints c = new GridBagConstraints();
//c.anchor = GridBagConstraints.NORTHWEST;
//add all images as buttons
List<PuzzleImage> imageList = _imageLoader.getImageCollection().getAllImages();
for(PuzzleImage puzzleImage : imageList) {
for(int i = 0; i < 1; i++) { //ignore this, just for debugging. i add 3 images
ImageIcon imageIcon = new ImageIcon(puzzleImage.getLowScaleImage());
c.gridx = x;
c.gridy = y;
c.weightx = 1.0;
JButton btn = new JButton(imageIcon);
btn.setPreferredSize(new Dimension(ImageLoader.LOW_SCALE_IMAGE_SIZE, ImageLoader.LOW_SCALE_IMAGE_SIZE));
panel.add(btn, c);
x++;
if(x>=4) {
x = 0;
y++;
}
}
}
return panel;
}
The last solution you linked is quite useful for controlling the delay of each item separatly.