Back to project page RICurrencyConversion-Android.
The source code is released under:
MIT License
If you think the Android project RICurrencyConversion-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.rocketinternet.currencyconversion; /* www. j ava 2 s. c om*/ import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; public class MyActivity extends Activity { private CurrencyConversionTask.OnCompleteListener<ConversionResult> _listener = null; private CurrencyConversionTask _task = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); final Double value = 40.05; final String currencyCode = "IDR"; final String targetCurrencyCode = "EUR"; _listener = new CurrencyConversionTask.OnCompleteListener<ConversionResult>() { @Override public void onComplete(ConversionResult conversionResult) { String msg = ""; if (conversionResult.getError() == null) { msg = String.format("%f %s converts to %f %s", value, currencyCode, conversionResult.getValue(), targetCurrencyCode); } else { msg = String.format("Conversion error: %s", conversionResult.getError().getMessage()); } Log.d(this.getClass().getName(), msg); Toast.makeText(MyActivity.this, msg, 10).show(); } }; CurrencyConversionInput input = new CurrencyConversionInput(value, currencyCode, targetCurrencyCode); _task = new CurrencyConversionTask(this, _listener); _task.execute(input); } @Override protected void onPause() { super.onPause(); if (_task != null) { _task.unregister(); } } @Override protected void onResume() { super.onResume(); if (_task != null) { _task.register(this, _listener); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.my, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }