I have a project that asks me to create a currency converter, I'm already looking for google and got some source that can give me a link, but I'm stuck when I click calculate, it does not change the text to the exchange rate.
I use json and this is the site
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22USDSGD%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
this is part of the code
calculate.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
TextView texts = (TextView) findViewById(R.id.textView3);
try {
s = getJson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22"+val[from]+val[to]+"%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");
JSONObject jObj;
jObj = new JSONObject(s);
String theResult = jObj.getJSONObject("query").getJSONObject("results").getJSONObject("rate").getString("Rate");
texts.setText(theResult);
}
catch (JSONException e) {
e.printStackTrace();
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
val [from] + val [to] comes from my counter, I have 2 spinner
getJson code
public String getJson(String url)throws ClientProtocolException, IOException {
StringBuilder build = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String con;
while ((con = reader.readLine()) != null) {
build.append(con);
}
return build.toString();
}
please help me .. where is not the code that I am already trying to edit and received nothing .. still when I click the button it does not give me a value for textview
source
share