The last step is to actually code the currency conversion. There's not much to it, you can look up your GUI elements with:
this.findViewById(R.id.<id>).
Here is the complete code for the CurrencyConverter activity:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
public class CurrencyConverter extends Activity implements OnClickListener {
TextView dollars;
TextView euros;
RadioButton dtoe;
RadioButton etod;
Button convert;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
dollars = (TextView)this.findViewById(R.id.dollars);
euros = (TextView)this.findViewById(R.id.euros);
dtoe = (RadioButton)this.findViewById(R.id.dtoe);
dtoe.setChecked(true);
etod = (RadioButton)this.findViewById(R.id.etod);
convert = (Button)this.findViewById(R.id.convert);
convert.setOnClickListener(this);
}
public void onClick(View v) {
if (dtoe.isChecked()) {
convertDollarsToEuros();
}
if (etod.isChecked()) {
convertEurosToDollars();
}
}
protected void convertDollarsToEuros() {
double val = Double.parseDouble(dollars.getText().toString());
// in a real app, we'd get this off the 'net
euros.setText(Double.toString(val*0.67));
}
protected void convertEurosToDollars() {
double val = Double.parseDouble(euros.getText().toString());
// in a real app, we'd get this off the 'net
dollars.setText(Double.toString(val/0.67));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
汇率转换app小程序(附源码)
共45个文件
class:11个
png:9个
xml:9个
3星 · 超过75%的资源 需积分: 18 82 下载量 77 浏览量
2014-05-09
14:42:15
上传
评论 3
收藏 1012KB ZIP 举报
温馨提示
使用Eclipse开发的第一个app应用,虽然比较粗糙,总体说来还算是成功的吧~
资源推荐
资源详情
资源评论
收起资源包目录
Convert.zip (45个子文件)
Convert
.project 843B
project.properties 563B
code.txt 2KB
src
com
example
convert
MainActivity.java 2KB
AndroidManifest.xml 878B
res
drawable-ldpi
drawable-hdpi
ic_launcher.png 7KB
menu
main.xml 223B
drawable-mdpi
ic_launcher.png 4KB
layout
activity_main.xml 2KB
values-sw600dp
dimens.xml 201B
drawable-xxhdpi
ic_launcher.png 24KB
drawable-xhdpi
ic_launcher.png 12KB
values
strings.xml 222B
styles.xml 695B
dimens.xml 218B
values-sw720dp-land
dimens.xml 275B
.settings
org.eclipse.jdt.core.prefs 177B
assets
gen
com
example
convert
BuildConfig.java 161B
R.java 3KB
libs
android-support-v4.jar 384KB
.classpath 364B
proguard-project.txt 781B
ic_launcher-web.png 50KB
bin
Convert.apk 193KB
resources.ap_ 40KB
classes
com
example
convert
R$layout.class 406B
R$style.class 434B
R$dimen.class 464B
BuildConfig.class 347B
R$drawable.class 410B
R$attr.class 343B
R$id.class 702B
R.class 683B
R$string.class 475B
R$menu.class 391B
MainActivity.class 2KB
AndroidManifest.xml 878B
dexedLibs
annotations-458932d5e145b72af62aab87c69fd6d1.jar 943B
android-support-v4-7dae89e704478dbb08cfa745eb4c395c.jar 148KB
jarlist.cache 119B
res
drawable-hdpi
ic_launcher.png 6KB
drawable-mdpi
ic_launcher.png 3KB
drawable-xxhdpi
ic_launcher.png 17KB
drawable-xhdpi
ic_launcher.png 9KB
classes.dex 442KB
共 45 条
- 1
资源评论
- syouyous2014-10-10比较简单,但实现了基本功能
- qq_209653472015-12-21只有两种汇率相互算 太简单
- qq_163106292015-02-28比较简单 适合初学者
- 脖子上的两层肉2014-12-06只有两种汇率相互算 太简
- linlindejia2015-01-12例子比较简单,汇率不是通过网络的实时汇率,定好了一个值直接计算得来的,帮助不大
gavin_joe
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功