0

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..

KD-21
  • 255
  • 2
  • 6
  • 16
  • You provide not enough information. How you detect "textfields" in the HTML? And how you want to detect count of textfields? Which tool you use to parse HTML? – Alexander Mikhaylov Apr 22 '14 at 09:52
  • My question is, how I can use the text out of an textview or Log. And use the text in a if then else of for loop or something. – KD-21 Apr 22 '14 at 10:05
  • I don't understand what you mean. To compare text with another text you can write like this: if (string.equals("blablabla")). If you don't understand why can't write if (string == "blablabla") you need to read something about java in general. To out text in log, you can write Log.d("tag", "blablabla"). It will print your text to android logcat. – Alexander Mikhaylov Apr 22 '14 at 10:19
  • Please show the html source. Show also the code where you are parsing the source. – greenapps Apr 22 '14 at 10:40
  • I have a ListView with text in it. Example: In the 1st textfield, there is in: "This is the first textfield", the 2nd textfield in the ListView shows: "This is the second textfield"....... When I make the for loop "i" = < 3. When I make it 10 the 10th texfield shows: "This is textfield ten".. Understand? But I'll stop the for loop if there is any textfield in the ListView who shows a specefic results. In this example it could be: "This is texfield seven". How can I detect and stop the for loop if there is any textfield in the ListView with "This is textfield seven" ??? – KD-21 Apr 22 '14 at 11:31
  • And when there is a textfield in the ListView with the text/results "This is textfield seven" the for loop need to stop.. And don't show or load the last 3 textfield. Even if I set the "i" in the for loop at 10. – KD-21 Apr 22 '14 at 11:32
  • So you are not using a for loop to put text from html in a listview (as you told in the first sentence). You use a for loop to iterate the items of a listview. Well show that code. – greenapps Apr 22 '14 at 11:42
  • It is to difficult to post my code.. The question is not so difficult.. How can I made an if with text what is in my listview? if(any textfield in my listview shows "blablabla") { do somthing! } else{ Log.e("blablabla") } – KD-21 Apr 22 '14 at 12:26

1 Answers1

0

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...

greenapps
  • 11,154
  • 2
  • 16
  • 19
  • I need to figure it out a little bit more.. Because my own code is a bit complexer.. But this is exactly what I need.. Thanks! – KD-21 Apr 23 '14 at 18:27