Unit Converter in Android Studio (JAVA)

package com.example.unconvert;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
private Button button;
private TextView textView2;
private EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
textView2 = findViewById(R.id.textView2);
editText = findViewById(R.id.edit2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Hi clicked Listner worked", Toast.LENGTH_SHORT).show();
String s = editText.getText().toString();
int kg = Integer.parseInt(s);
double pound = 2.205 * kg;
textView2.setText(""+pound);
}
});
}
}

Comments

Post a Comment