I am creating an app for currency exchanging. To Convert USD to foreign currencies. I have created an app but the problem is that I have to manually update the rate for the currency. Is their anyway for my app to get the rates to automatically update by itself. Here is my java code for the app. Look in my function for ConvertUSDtoEuro() and ConvertEurotoUSD(). I hope everything was clear.
package com.example.currencyconverter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
public class MainActivity extends Activity
{
private EditText text;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (EditText) findViewById(R.id.editText1);
}
public double ConvertUSDtoEuro(float USD)
{ return ((USD * .667)); }
public double ConvertEurotoUSD(float Euro)
{ return ((Euro * 1.11)); }
public void onClick (View view)
{
switch (view.getId())
{
case R.id.button1:
RadioButton USDButton = (RadioButton) findViewById(R.id.radio0);
RadioButton EuroButton = (RadioButton) findViewById(R.id.radio1);
float inputvalue = Float.parseFloat(text.getText().toString());
if (USDButton.isChecked())
{
text.setText(String.valueOf(ConvertUSDtoEuro(inputvalue)));
USDButton.setChecked(true);
EuroButton.setChecked(false);
}
else
{
text.setText(String.valueOf(ConvertEurotoUSD(inputvalue)));
USDButton.setChecked(false);
EuroButton.setChecked(true);
}
break;
}
}
}