Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dibello.paolo.test;
- import android.app.Activity;
- import android.R.*;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- EditText ed1;
- TextView resu;
- Button btn;
- RadioButton ce_to_fa,fa_to_ce;
- @Override
- protected void onCreate(Bundle savedInstanceState) {//Start of oncreate
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main); //Call layout
- //***Call View IDs allway before do some stuff with them
- ed1=(EditText)findViewById(R.id.editText);
- resu=(TextView)findViewById(R.id.textView);
- ce_to_fa=(RadioButton)findViewById(R.id.radioButton);
- fa_to_ce=(RadioButton)findViewById(R.id.radioButton2);
- btn=(Button)findViewById(R.id.button);
- //***Call View IDs end!
- show_toast("Ciao, guarda come sono educato!");
- btn.setOnClickListener(new View.OnClickListener() { //Start button click
- @Override
- public void onClick(View view) {
- if(ed1.length()==1||ed1.length()>1){
- int a = Integer.parseInt(ed1.getText().toString()); //This is textbox one
- if(fa_to_ce.isChecked()){
- resu.setText(Double.toString((a-32.0) * 5.0/9.0)); //Show result to textview
- }else(ce_to_fa.isChecked()){
- resu.setText(Double.toString((a*9.0)/5.0+32.0)); //Show result to textview
- }
- }else{
- if(ed1.length()==0){
- //now i call show_toast and paste message there
- show_toast("Scrivere, casella vuota");
- }
- }
- }
- });
- }
- public void show_toast(String message){
- Toast.makeText(MainActivity.this,
- message, Toast.LENGTH_LONG).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement