次のように、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();
}
文字列「行」には、本来のように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」は空であることがわかります。
では、文字列「行」の内容を取得するにはどうすればよいですか?
ご協力ありがとうございました。
編集: 読み込もうとしている html は次のようなものです (必要に応じて変更できます。これは私のサイトです):
a
-
1 8
0 ./immagini/Opera_img.jpg
2 Opera
3 Io
4 finto
5 1999-11-11