2016-04-03 44 views
-1

için görüntülenmiyor. Android Studio'da yerel bir HTML sayfasından veri ayıklamıyorum ve görüntülendiği her şey boş bir ekran olarak gösteriliyor. Kazıdığım verileri nasıl görüntüleyeceğimi bilen var mı? Aşağıda ana kod parçasıdır.Doğru Veriler, Android-Android

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    try { 
     StringBuilder buf=new StringBuilder(); 
     InputStreamReader inputStream = new InputStreamReader(getAssets().open("filename.html")); 
     BufferedReader bufferedReader = new BufferedReader(inputStream); 
     String str; 
     while ((str=bufferedReader.readLine()) != null) { 
      buf.append(str); 
     } 
     Document doc = Jsoup.parse(buf.toString()); 
     StringBuilder sb = new StringBuilder(); 

     Elements tableElements = doc.select("td[colspan='1']"); 
     TextView textView = (TextView)findViewById(R.id.text_view); 
     for (Element td : tableElements) { 
      sb.append(td.text() + "\n"); 
      System.out.println(td.text()); 
     } 
     textView.setText(sb.toString()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

} , bu Pazartesi ı görüntülemek istediğiniz yaptığı gibi 9:00 ve benzeri zamanlardır sadece monday.the gerisi çok uzun ama devam eder

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     <html xmlns='http://www.w3.org/1999/xhtml'> 
    <head><title>timetable.html</title><meta http-equiv='content-disposition', content='attachment;filename=timetable.html'> 
    <meta http-equiv="Content-Type" content="application/octet-stream" /> 

    <style>body {background-color:white;} body,td { font-family: arial; }  </style></head> 
    <data> 
      <body> 
      <table cellspacing='0' border='0' width='100%' > 
      <col align='left' /><col align='center' /><col align='right' /> 
     </data> 
      <tr> 
     <td></td><td></td><td></td> 
    </tr> 
    </table> 
    </td> 
    </tr><tr> 
    <td> 
    <table cellspacing='0' border='0' width='100%' > 
    <col align='left' /><col align='center' /><col align='right' /> 
    <tr> 
    <td></td><td></td><td></td> 
    </tr> 
    </table> 
    </td> 
    </tr><tr> 
    <td> 
    <table cellspacing='0' border='0' width='100%' > 
    <col align='left' /><col align='center' /><col align='right' /> 
    <tr> 
    <td></td><td></td><td></td> 
    </tr> 
    </table> 
    </td> 
    </tr><tr> 
    <td> 
    <table cellspacing='0' border='0' width='100%' > 
    <col align='left' /><col align='center' /><col align='right' /> 
    <tr> 

     <td><table border='0' width='100%'><tr><td width='40%' align='left' valign='middle'><font face='arial' size='3'><b>The Year<font size='1'> </td><td width='20%' align='center' valign='middle'><font face='arial' size='1'>ICOM</td>  <td width='40%' align='right' valign='middle'><font face='arial' size='2'>  <b>Weeks selected for output: 26 (22 Feb 2016-28 Feb 2016)</td></td><td></td> <td></td> 
    </tr> 
     </table> 
     </td> 
     </tr> 
     </table> 
     <table cellspacing='0' border='1'> 
     <tr> 
     <td></td> 

     <td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>9:00</font>   </td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>9:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>9:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>9:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>10:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>10:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>10:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>10:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>11:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>11:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>11:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>11:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>12:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>12:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>12:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>12:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>13:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>13:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>13:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>13:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>14:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>14:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>14:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>14:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>15:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>15:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>15:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>15:45</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>16:00</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>16:15</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>16:30</font></td> 
<td bgcolor='#C0C0C0' colspan='1'><font color='#FFFFFF'>16:45</font></td> 
      </tr> 
     <tr > 
     <td style="border-bottom:3px solid #000000;" rowspan='1' bgcolor='#C0C0C0'><font color='#FFFFFF'>Monday</font></td> 
     <td style="border-bottom:3px solid #000000;" colspan='12' rowspan='1' > 

     <table cellspacing='0' border='0' width='100%'> 
    <col align='left' /> 
    <tr> 
    <td align='left'><font color='#FF0000'>Sound</font></td> 
    </tr> 
    </table> 
    <table cellspacing='0' border='0' width='100%'> 
    <col align='left' /> 
    <col align='right' /> 
    <tr> 
    <td align='left'><font color='#000000'>P2016</font></td> 
    <td align='right'><font color='#008000'>P.Man</font></td> 
     </tr> 
     </table> 
    <table cellspacing='0' border='0' width='100%'> 
    <col align='left' /> 
    <tr> 
    <td align='left'><font color='#000080'>22-29, 32-36</font></td> 
    </tr> 
    </table> 

     </td> 
    <td style="border-bottom:3px solid #000000;" >&nbsp;</td> 
    <td style="border-bottom:3px solid #000000;" >&nbsp;</td> 
    <td style="border-bottom:3px solid #000000;" >&nbsp;</td> 
    <td style="border-bottom:3px solid #000000;" >&nbsp;</td> 
    <td style="border-bottom:3px solid #000000;" colspan='4' rowspan='1' > 

    <table cellspacing='0' border='0' width='100%'> 
    <col align='left' /> 
     <tr> 
    <td align='left'><font color='#FF0000'>Ship</font></td> 
    </tr> 
     </table> 
    <table cellspacing='0' border='0' width='100%'> 
    <col align='left' /> 
    <col align='right' /> 
    <tr> 
    <td align='left'><font color='#000000'>P2015</font></td> 
    <td align='right'><font color='#008000'>K.Loin</font></td> 
    </tr> 
     </table> 
    <table cellspacing='0' border='0' width='100%'> 
    <col align='left' /> 
    <tr> 
    <td align='left'><font color='#000080'>22-29, 32-36</font></td> 
     </tr> 
     </table> 

     </td> 
     <td style="border-bottom:3px solid #000000;" colspan='12' rowspan='1' > 

     <table cellspacing='0' border='0' width='100%'> 
     <col align='left' /> 
     <tr> 
     <td align='left'><font color='#FF0000'>Mobility</font></td> 
     </tr> 
     </table> 
     <table cellspacing='0' border='0' width='100%'> 
     <col align='left' /> 
     <col align='right' /> 
     <tr> 
     <td align='left'><font color='#000000'>P2222</font></td> 
     <td align='right'><font color='#008000'>D.Met</font></td> 
     </tr> 
     </table> 
     <table cellspacing='0' border='0' width='100%'> 
     <col align='left' /> 
     <tr> 
     <td align='left'><font color='#000080'>22-29, 32-36</font></td> 
     </tr> 
    </table> 

     </td> 
    </tr> 

Onun bir takvim HTML 9: 15, Pazartesi, Ses, P2016, P.Man, Gemi, K.Lion, P2015

+0

Konsolda doğru çıktı alıyor musunuz? Metin Görünümü'nü yalnızca bir metin ayarladıysanız görünür mü? – BadCash

+0

Bazı günlükleri paylaşabilir misiniz? buf.toString() öğesini yazdırırken ne elde edersiniz ve dokümanda neler var? –

cevap

0

bunu yapın, bu previous question dayanmaktadır:

Document doc = Jsoup.parse(buf.toString()); 
StringBuilder sb = new StringBuilder(); 

Elements tableElements = doc.select("td[colspan='1']"); 
TextView textView = (TextView)findViewById(R.id.text_view); 
for (Element td : tableElements) { 
    sb.append(td.text() + "\n"); 
    System.out.println(td.text()); 
} 
textView.setText(sb.toString()); 
+0

getText() biti ile ilgili bir hatam var, onu content_main içinde tanımlamalı mıyım? – DW41

+0

hangi hatayı alıyorsunuz? –

+0

yöntemi çözemiyor getText() – DW41