1

I need to parse data table look like this:

<table width="75%" border="2" id="INVALSI">
    <tbody>
        <tr>
            <td width="5%" align="center"><strong>UNITA'<br>SINTATTICA
            </strong></td>
            <td width="45%" align="center"><strong>ANALISI<br>LOGICA
            </strong></td>
            <td width="50%" align="center"><strong>RISPONDE<br>ALLA
                    DOMANDA:
            </strong></td>
        </tr>
        <tr>
            <td align="left" style="padding: 4px 4px 2px 6px;"><strong>ciao</strong></td>
            <td align="left" style="padding: 4px 4px 2px 6px;"><strong>complemento
                    vocativo (o esclamativo)</strong></td>
            <td align="left" style="padding: 4px 4px 2px 6px;"><strong>CI
                    SI INDIRIZZA A QUALCUNO?</strong><br></td>
        </tr>
    </tbody>
</table>

How can I select the "strong" and parse it into a listview?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3437592
  • 59
  • 3
  • 9

2 Answers2

1

You ca use Jsoup HTML parser to get the required data

Step 1. Download the jsoup.jar from http://jsoup.org/download

Step 2. Add it to the libs folder of your project.

Step 3. Extract Data required

    ArrayList<String> list = new ArrayList<String>();
    Document doc = Jsoup.parse("your html");  
    Elements elements = doc.select("strong");
    for(int i=0;i<elements.size();i++)
    {

        list.add(elements.get(i).text().toString());

    }

Finally

ArrayAdapter<String> adapter = new ArrayAdapter<String>(ActivityName.this,android.R.layout.simple_list_item_1,list);
listview.setAdapter(adapter);
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Just curious, whats the different between using `List list` and `ArrayList list`? – TMH May 27 '14 at 13:01
  • @TomHart lots of similar questions on SO http://stackoverflow.com/questions/2279030/type-list-vs-type-arraylist-in-java. search one of them you will find your answer. one more http://stackoverflow.com/questions/20766101/liststring-vs-arrayliststring – Raghunandan May 27 '14 at 13:04
0

As CommonsWare sayed in this post

There are many HTML parsers : http://java-source.net/open-source/html-parsers

Community
  • 1
  • 1
Florian Mac Langlade
  • 1,863
  • 7
  • 28
  • 57