In my app I have the WebView which shows html files. So I want to get all links from the displayed file and put them into another activity with listview.
For example:
I have following links in the displayed file:
<a href="somelink1.html">SomeLink1</a>
<a href="somelink2.html">Somelink2</a>
and I want to show titles of these links in ListView, click on the item will open the appropriate file.
Here is the code of ListView in which I want to show these links:
public class ListWithLinks extends Activity
{
private ListView lv1;
private String lv_arr[]
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv1 = (ListView)findViewById(R.id.listView);
lv1.setAdapter(new ArrayAdapter<String>(this, R.id.list, lv_arr));
lv1.setTextFilterEnabled(true);
lv1.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> a, View v, int position, long id)
{
//my stuff
}
}
}
So I need to populate the list with titles and assign each element with the appropriate link.
How can I do that? Help, please.
There are many HTML parsing libraries, like for example jsoup. You can find very simple and clear example in one of the Cookbook pages here.
Hope this helps,
Serhiy.