I have a project that ask me to build a currency converter, i already search google and got some source that can give me a reference
but i got stuck when i click calculate it doesnt change the textview to the rate of the currency..
I using a 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 some 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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
the val[from]+val[to] is come from my spinner, i have 2 spinner
the 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 the wrong of this code i already try to edit and got nothing .. still when i click the button it dont give me the value to textview
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…