I am having an issue with parsing the following website:
http://www.x-rates.com/d/USD/table.html
I am very, very very new to android programming and I am thinking about creating a currency converter, now I know that there is a bunch out there however, I am trying to fast track my programming initiation and get myself immersed in code.
I found a tutorial that tried to explain and it was helpful for a website with the need for a specific item. the code is below:
package com.ve.webgrab;
import java.io.IOException;
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.view.View;
public class WebgrabActivity extends ListActivity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
ArrayList<String> tableRowStrings = new ArrayList<String>();
Document doc = null;
try {
doc = Jsoup.connect("http://www.x-rates.com/d/USD/table.html").get();
}
catch (IOException e) {
e.printStackTrace();
}
String testString = "American";
Elements tableRows = doc.select("tr");
for (Element tableRow : tableRows){
if (tableRow.hasText()){
String rowData = tableRow.text();
if(rowData.contains(testString)){
tableRowStrings.add(rowData);
}
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tableRowStrings);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
I need to be able to get the table with the usd to other currency so that I can have it in a database and then use it for the conversion. I believe the section that I need to look at is:
String testString = "American";
Elements tableRows = doc.select("tr");
for (Element tableRow : tableRows){
if (tableRow.hasText()){
String rowData = tableRow.text();
if(rowData.contains(testString)){
tableRowStrings.add(rowData);
}
}
}
What I need to accomplish:
Get the website:- - I believe this is accomplished:-
doc = Jsoup.connect("http://www.x-rates.com/d/USD/table.html").get();
Select the table on the website with particular interest on the Conversion rate: - Still cannot figure this part out.
Test for the Table to ensure it is the correct one:
String testString = "American"; if(rowData.contains(testString)){
Take the data on the table and display to a list view just to ensure that the correct data is being gathered:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tableRowStrings); setListAdapter(adapter);
Break up the table
<td>
into country and conversion rate and then place it into a database.
I am looking for guidance, please remember that I am totally new to this and I want to build out this app for a learning experience and a spring board to bigger and better apps, example code is definitely welcome, I would appreciate all the help I can get.