Java 在onBindviewHolder中使用不带循环的标签
我正在尝试使用以下代码:Java 在onBindviewHolder中使用不带循环的标签,java,android,label,Java,Android,Label,我正在尝试使用以下代码: @Override public void onBindViewHolder(final ViewHolder holder, final int position) { label :{ if(some condition) { //my code } else { if(my condition) { //some code
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
label :{
if(some condition) {
//my code
} else {
if(my condition) {
//some code
continue label; // from here i want to go back to label, how to i go?
}
}
}
}
行继续标签;给我这个错误:不是循环标签
所以我需要回到“label”这行,我该怎么做呢?为什么要使用“label”循环 尝试使用while循环,如下所示:
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
while (true) {
if (some condition) {
// my code
break; // if this code ran then exit the while loop
} else if (my condition) {
// some code
continue; // from here it will make another iteration in the while loop
}
}
}
您可以使用continue关键字来跳过循环中的迭代
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
while (true) {
if(some condition) {
//my code
} else {
if(my condition) {
//some code
continue ; // skipping this iteration
}
}
}
}
但这是在onbindviewholder中,如何将其放入while循环中?@ParthAnjaria我编辑了代码以使其更清晰。您只需将while循环放在onBindViewHolder()方法中。还有什么不清楚的地方吗?你尝试过我发布的while循环解决方案吗?它在BindView中不起作用。你能更好地解释一下你想要实现什么吗?如果要通过编程方式调用onBindViewHolder()方法,可以使用bindVIewHolder()来实现。更多信息请参见,int)