I am trying to add an element to ArrayList
after every 4 items.
ArrayList
after this should be like,
item|item|item|item|new_item|item|item|item|item|new_item|item...
So I use the code
int x=0;
for (int i=1;i<myNews.size();i++) {
if (i%4==0) {
NewsData news = new NewsData();
news.setId(999);
news.setItem_type(3);
news.setCat_id(97);
myNews.add(i+x,news);
x++;
}
}
This doesn't seem to work as required. How would I achieve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…