I am using this to get a list of elements from a webpage. http://www.gamespy.com/index/release.html
// Get all the game elements
Elements games = doc.select("div.FP_Up_TextWrap b");
// Create new ArrayList
ArrayList<String> gameList = new ArrayList<String>();
// Iterator over those elements
ListIterator<Element> postIt = games.listIterator();
while (postIt.hasNext()) {
// Add the game text to the ArrayList
gameList.add(postIt.next().text());
}
This returns all the tags with which is what I want. But it returns the full tag with the title I just want the title the release date and a Img sr. I would like to return it to a list view. How would I go about doing this? I maybe doing it totally wrong so you guys may want to check out the HTML page source.
EDIT - Gives me NullPointer error
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outputTextView = (TextView)findViewById(R.id.outputTextView);
ListView list = (ListView)findViewById(R.id.list);
ArrayList<String> gameList = new ArrayList<String>();
Document doc = null;
try {
doc = Jsoup.connect("http://www.gamespy.com/index/release.html").get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get all td's that are a child of a row - each game has 4 of these
Elements games = doc.select("tr > td.indexList1, tr > td.indexList2");
// Iterator over those elements
ListIterator<Element> postIt = games.listIterator();
while (postIt.hasNext()) {
// Add the game text to the ArrayList
gameList.add(postIt.next().text());
}
String[] items = new String[gameList.size()];
gameList.toArray(items);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, items);
// error points here
list.setAdapter(adapter);
}
}
EDIT - Layout for the list
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/outputTextView"
/>
<ListView android:layout_height="wrap_content" android:id="@+id/list" android:layout_width="match_parent"></ListView>
</LinearLayout>