简体   繁体   English

如何从TextView或ListView Android中获取文本?

[英]How to get text out of TextView or ListView Android?

I have a ListView. 我有一个ListView。 This ListView load this text/data from a URL/HTML code on a webpage. 此ListView从网页上的URL / HTML代码加载此文本/数据。 I use a for loop for it like: 我为它使用for循环:

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.. 但是有时该网页有5个“文本字段”,但也许一个新帖子有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循环中使用5。我想要一个正在加载和加载的for循环,直到他在网页的html代码中找到特定行为止。

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.. 有时他需要在3个文本字段之后停止。.但是另一次他需要在16个文本字段之后停止。

I hope I was clear enough. 我希望我足够清楚。

Thanks, 谢谢,

PS 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.. PS目前,我所有的代码都在工作。.当我使用for循环系统时,请手动计算HTML中的文本字段。.将值放入for循环中,然后代码将加载所有文本字段。.但是我要自动..

Use the break; 使用休息; statement to break out of your for loop. 语句打破您的for循环。 You can initiate the for loop with a big number like 5000. 您可以使用5000这样的大数字来启动for循环。

 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM