我正在尝试处理我使用 BufferReader 读取的 html,如下所示:
try {
HttpResponse response = DisplayMessageActivity.httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
String line="";
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
char c = 'z';
line = rd.readLine();
c = line.charAt(0);
switch(c){
case 'a':
mainListView = (ListView) findViewById(R.id.listView);
String titolo = "";
final ArrayList<String> listaTitoli = new ArrayList<String>();
while ((line = rd.readLine()) != null) {
System.out.println(line);
if(line.startsWith("2")){
titolo = line.substring(2, (line.length()-4));
System.out.println(titolo);
listaTitoli.add(titolo);
}
}
if(!listaTitoli.isEmpty()){
listAdapter = new ArrayAdapter<String>(URLHandlerActivity.this, R.layout.list_element, listaTitoli);
mainListView.setAdapter(listAdapter);
}
break;
case 'b':
break;
case 'c':
break;
case 'd':
break;
case 'e':
break;
}
rd.close();
}
字符串“line”包含应有的html代码(我从logcat中读取),但程序从不输入“if(line.startsWith(“2”))”。发生这种情况我也尝试这样做:
String str = "";
char c = 'z';
while ((line = rd.readLine()) != null){
System.out.println(line);
str = line.substring(0);
System.out.println(str);
c = line.charAt(0);
System.out.println(c);
...
...
}
而在logcat中,虽然“line”包含html行,但“str”和“c”都是空的。
那么我怎样才能得到字符串“line”的内容呢?
谢谢您的帮助。
编辑:我正在尝试阅读的 html 是这样的(如有必要,我可以更改它,这是我的网站):
a
-
1 8
0 ./immagini/Opera_img.jpg
2 Opera
3 Io
4 finto
5 1999-11-11