Skip to content

Instantly share code, notes, and snippets.

@ForceGT
Last active July 21, 2020 12:37
Show Gist options
  • Save ForceGT/869a987c08e711ba54dacd494b872ba4 to your computer and use it in GitHub Desktop.
Save ForceGT/869a987c08e711ba54dacd494b872ba4 to your computer and use it in GitHub Desktop.
package com.myappcompany.rob.currencyconverter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button;
public void convertCurrency(View view) {
Log.i("Info", "Button pressed");
EditText editText = (EditText) findViewById(R.id.editText);
String amountInDollar = editText.getText().toString();
double amountIninrDouble = Double.parseDouble(amountInDollar);
double amountInDollarsDouble = amountIninrDouble * 75;
String amountInINRString = String.format("%.2f", amountInDollarsDouble);
Toast.makeText(this, "$ " + amountInDollar + " is INR " + amountInINRString, Toast.LENGTH_LONG).show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// don't forget to call the method here if you don't do it through xml
//Remember to do only one
Log.i("Info", "Button pressed");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment