I have a ListView. This ListView load this text/data from a URL/HTML code on a webpage. I use a for loop for it like:

for (int i = 0; i < 5; j++) { 
// Search and load text in the ListView.. 
}

But sometimes the webpage has 5 "textfields" but maybe a new post got 8..

So, I don't want to use the 5 in the for loop anymore.. I want a for loop which is loading and loading untill he find a specific line in the html code of the webpage.

For example:

if (MaxLoad != "<p>End of the textfields</p>") {
     // Search and load text in the ListView, 
     // untill the found text is the text between the "". 
   }
}

else{
Log.e("Max textfields are found!")
}

Sometimes he need to stop after 3 textfields.. But another time he need to stop after 16 textfields..

I hope I was clear enough.

Thanks,

P.S. All my code is working at the moment.. When I use the for loop system, count the textfields in the HTML manually.. Put that value into the for loop, then the code load all the textfields.. But I want it automaticly..

有帮助吗?

解决方案

Use the break; statement to break out of your for loop. You can initiate the for loop with a big number like 5000.

 for (int i = 0; i < 5000; j++) { 
 // Search and load text in the ListView.. 
 String ItemText = .......


 if ( ItemText.equals ( "blablabla" ) )
    break;
}

This could be done more elegant though...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top