Know led

A light bulb that never burns out

May 5, 2013

Android JSOUP Parsing Tables fromWeb Sites

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 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.

cchinchoy

May 5, 2013

Theorist Marshall McLuhan postulated that you would become

You would become the message.

The medium is the message–possibly derived from an R. W. Emerson quote, “The human body is the magazine of inventions, the patent-office, where are the models from which every hint was taken. All the tools and engines on earth are only extensions of its limbs and senses” (1870).

[See also writings about propaganda by Samuel Ichiye Hayakawa)

May 5, 2013

What is the word for hot in different languages

This may be important to travelers who find the initial C on the hot water tap!

Spanish – caliente
French – chaud
German – heiss (heiß)
Dutch – hot
Italian – caldo
Portuguese – quente
Polish – gorąco

Russian – горячий (ga-rya-chiiy)
Chinese – 热 (reh)
Japanese – ホット (atsui)

Older Posts