Skip to content

Instantly share code, notes, and snippets.

Last active July 21, 2020 12:37
What would you like to do?
package com.myappcompany.rob.currencyconverter;
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(;
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();
protected void onCreate(Bundle savedInstanceState) {
button= findViewById(;
button.setOnClickListener(new View.OnClickListener() {
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