Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在onBindviewHolder中使用不带循环的标签_Java_Android_Label - Fatal编程技术网

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)