已经把更新的项目SVN到SF上了,地址: 复制我
先main.xml:
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <Spinner android:layout_height="wrap_content" android:id="@+id/Spinner01" android:layout_width="wrap_content" android:layout_x="16dip" android:layout_y="13dip"></Spinner> <Spinner android:layout_height="wrap_content" android:id="@+id/Spinner02" android:layout_width="wrap_content" android:layout_x="133dip" android:layout_y="14dip"></Spinner> <EditText android:layout_height="wrap_content" android:layout_width="170px" android:text="" android:textSize="18sp" android:id="@+id/EditText01" android:layout_x="13dip" android:layout_y="101dip"></EditText> <Button android:layout_height="wrap_content" android:text="转换" android:layout_width="wrap_content" android:id="@+id/Button01" android:layout_x="240dip" android:layout_y="98dip"></Button> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/TextView01" android:layout_x="113dip" android:layout_y="220dip"></TextView> </AbsoluteLayout>
然后sources:
package com.overflow.moneydroid; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; public class Activity01 extends Activity { private final String DEBUG_TAG = "MoneyDroid"; private static final String[] moneyName = {"CNY", "HKD","TWD","EUR","USD","GBP","AUD","KRW","JPY"}; private TextView textview = null; private Button button = null; private Spinner spinner1 = null; private Spinner spinner2 = null; private EditText edittext = null; static String sp1 = ""; static String sp2 = ""; static String edt = ""; private ArrayAdapter<String> adapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textview = (TextView) this.findViewById(R.id.TextView01); button = (Button) this.findViewById(R.id.Button01); spinner1 = (Spinner) this.findViewById(R.id.Spinner01); spinner2 = (Spinner) this.findViewById(R.id.Spinner02); edittext = (EditText) this.findViewById(R.id.EditText01); adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,moneyName); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(adapter); spinner2.setAdapter(adapter); spinner1.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub sp1 = moneyName[arg2]; Log.e(DEBUG_TAG, sp1); arg0.setVisibility(View.VISIBLE); } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); spinner2.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub sp2 = moneyName[arg2]; Log.e(DEBUG_TAG, sp2); arg0.setVisibility(View.VISIBLE); } public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); button.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub //textview.setText("ok"); String httpUrl = "http://www.123cha.com/hl/?q="+edittext.getText().toString()+ "&from="+sp1+"&to="+sp2+"&s="+ sp1+sp2+"#symbol="+sp1+sp2+"=X;range=3m;"; //构造一个URL对象 String resultData = ""; URL url = null; try { url = new URL(httpUrl); } catch (MalformedURLException e) { Log.e(DEBUG_TAG, "MalformedURLException"); } if (url != null) { try { // 使用HttpURLConnection打开连接 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); //得到读取的内容(流) InputStreamReader in = new InputStreamReader(urlConn.getInputStream()); // 为输出创建BufferedReader BufferedReader buffer = new BufferedReader(in); String inputLine = null; String matcherLine = null; //使用循环来读取获得的数据 Pattern pattern = Pattern.compile("<td>(.+?)</td><td>(.+?)</td><td>(.+?)</td>",Pattern.DOTALL); while (((inputLine = buffer.readLine()) != null)) { //我们在每一行后面加上一个"\n"来换行 resultData += inputLine + "\n"; Matcher matcher = pattern.matcher(resultData); if (matcher.find()) { Log.e(DEBUG_TAG, matcher.group()); matcherLine = matcher.group(3).trim(); } } //关闭InputStreamReader //Log.e(DEBUG_TAG,httpUrl); in.close(); //关闭http连接 urlConn.disconnect(); //设置显示取得的内容 if ( matcherLine != null ) { textview.setText(matcherLine); } else { textview.setText("读取的内容为NULL"); } } catch (IOException e) { Log.e(DEBUG_TAG, "IOException"); } } else { Log.e(DEBUG_TAG, "Url NULL"); } } }); } }
要在manifest.xml里加入网络权限,东西写的太简陋,正则很慢,很费流量,更好的办法应该是更新汇率到本地数据库,然后本地来计算汇率。
您还没有登录,请您登录后再发表评论
JAVA代码能实现多种货币转换,有抛出异常,图形界面
一个简洁的汇率转换软件,使用 kotlin 编写,通过 anko 框架编写 UI 并实现漂亮的主题动态切换效果
人民币市场汇率改革步骤---陆前进.ppt
Mac下的汇率转换器开发 Cocoa入门----使用Objective-C
汇率转换(调用谷歌-雅虎API)...在这里,将使用谷歌、雅虎的API展示一个实时汇率转换器。 在该源码中,已经创建了一个web应用程序,调用谷歌或雅虎的api,使用jQuery Ajax和web服务把用户输入的数据转换并显示在用户界面。
汇率转换
NIFD季报-度人民币汇率-20211-20页.pdf
财务管理3第三章外汇、汇率与汇率决定理论-杨虎锋.pptx
简洁、轻量的谷歌汇率转换小工具。 @ChangeLog: + 0.4.5 20190409 * 大幅降低首屏加载时间 * 调整界面布局与文字大小 + 0.4.4 20190327 * 增加打开时自动获取当前选中数字的功能 + 0.4.3 20190326 * 货币过滤器...
航空行业:航空反弹已开启,需求汇率双催化-0918-国泰君安-11页.pdf
本pdf文件包含所有操作步骤,教你如何做一个汇率转换器
2月银行结售汇数据分析:结售汇顺差环比减少,但结售汇率差回升-20210323-银河期货-11页
HTML 汇率换算工具源码,支持 51 种不同的货币汇率相互转换换算。数据实时自动更新,界面简洁,代码易懂
基于eclipse的Android例子源码美元和欧元汇率转换小程序,简单的汇率转换,用于完成安卓课程设计。
php实时汇率转换,从yahoo调用的接口
电大作业-汇率-调查人民币汇率变化-分析人民币短期汇率走势及其影响.docx
电大作业-汇率-调查人民币汇率变化-分析人民币短期汇率走势及其影响.pdf
相关推荐
JAVA代码能实现多种货币转换,有抛出异常,图形界面
一个简洁的汇率转换软件,使用 kotlin 编写,通过 anko 框架编写 UI 并实现漂亮的主题动态切换效果
人民币市场汇率改革步骤---陆前进.ppt
Mac下的汇率转换器开发 Cocoa入门----使用Objective-C
汇率转换(调用谷歌-雅虎API)...在这里,将使用谷歌、雅虎的API展示一个实时汇率转换器。 在该源码中,已经创建了一个web应用程序,调用谷歌或雅虎的api,使用jQuery Ajax和web服务把用户输入的数据转换并显示在用户界面。
汇率转换
NIFD季报-度人民币汇率-20211-20页.pdf
财务管理3第三章外汇、汇率与汇率决定理论-杨虎锋.pptx
简洁、轻量的谷歌汇率转换小工具。 @ChangeLog: + 0.4.5 20190409 * 大幅降低首屏加载时间 * 调整界面布局与文字大小 + 0.4.4 20190327 * 增加打开时自动获取当前选中数字的功能 + 0.4.3 20190326 * 货币过滤器...
航空行业:航空反弹已开启,需求汇率双催化-0918-国泰君安-11页.pdf
本pdf文件包含所有操作步骤,教你如何做一个汇率转换器
2月银行结售汇数据分析:结售汇顺差环比减少,但结售汇率差回升-20210323-银河期货-11页
HTML 汇率换算工具源码,支持 51 种不同的货币汇率相互转换换算。数据实时自动更新,界面简洁,代码易懂
基于eclipse的Android例子源码美元和欧元汇率转换小程序,简单的汇率转换,用于完成安卓课程设计。
php实时汇率转换,从yahoo调用的接口
电大作业-汇率-调查人民币汇率变化-分析人民币短期汇率走势及其影响.docx
电大作业-汇率-调查人民币汇率变化-分析人民币短期汇率走势及其影响.pdf