I am creating an Android app based on The Legend of Zelda, I wanted to link to the Wikia pages for the Zelda video games located at: http://zelda.wikia.com/wiki/Category:Games ; I was wondering if there was a way to get the page names for each game and import them to a listview in my Android app. The way that I am currently doing this is directly coding the names of the games into the app itself, but if I could do it so it would pull the names for me then I wouldn’t have to update every time that a new game comes out, and it would save on hard coding all of these names in there. The code I have so far is as follows:
package com.lvlup.kikurself.zeldatest;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class zeldaGames extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String[] values = new String[] { "The Legend of Zelda", "Zelda II: The
Adventure of Link", "The Legend of Zelda: Ocarina of Time",};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
final ListView zeldaList = getListView();
zeldaList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long thisID)
{
Object o = (zeldaList.getItemAtPosition(position));
String gameName_temp = (o.toString());
Intent newIntent = new Intent(v.getContext(), gameDisp.class);
newIntent.putExtra("tempG", gameName_temp);
startActivity(newIntent);
}
});
Any help is greatly appreciated, thank you for taking the time to read this.
I have been looking at the MediaWiki API and have found this:
http://zelda.wikia.com/api.php?action=query&list=categorymembers&cmtitle=Category:Games&cmlimit=500
This will list the games but it is in xml format I am still confused as to how i would get the game titles to enter into my list. Please help or point me in the right direction.
best bet would be to use
HTML Parserand parse the content you need to display.Here is Java implementation of
HTML Parserhttp://htmlparser.sourceforge.net/
another one
http://jtidy.sourceforge.net/
You need to look for
<div class="category-gallery">particularDIVwhich will be constant for every game page.Inside that
DIV, every game is listed inside anotherDIVwhich have content like Name, URL, Image, etc…
from here you can parse the stuff you need. This also works fast enough, so no need to worry about performance.