Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. package com.example.testexample;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.provider.MediaStore;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.RadioButton;
  12. import android.widget.RadioGroup;
  13. import android.widget.Toast;
  14.  
  15. import javax.xml.transform.Result;
  16.  
  17.  
  18. public class MainActivity extends AppCompatActivity {
  19.     public static final String EXTRA_HINPUT = "com.example.application.example.EXTRA_HINPUT";
  20.     public static final String EXTRA_WINPUT = "com.example.application.example.EXTRA_WINPUT";
  21.     public static final String IS_MALE = "is_male";
  22.     public static final String EXTRA_FEMALE = "com.example.application.example.EXTRA_FEMALE";
  23.  
  24.  
  25.    
  26.     @Override
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_main);
  30.  
  31.         Button calcbtn = (Button) findViewById(R.id.calculatebtn);
  32.         calcbtn.setOnClickListener(new View.OnClickListener() {
  33.             @Override
  34.             public void onClick(View v) {
  35.                 openResultActivity();
  36.             }
  37.         });
  38.     }
  39.  
  40.  
  41.     public void onRadioButtonClicked(){
  42.         RadioButton malebtn = (RadioButton)findViewById(R.id.malebtn);
  43.         Intent RadioIntent = new Intent(this , ResultActivity.class);
  44.  
  45.         if(malebtn.isChecked()){
  46.             RadioIntent.putExtra(IS_MALE, true);
  47.             Toast.makeText(getApplicationContext(),"Male Selected",Toast.LENGTH_SHORT).show();
  48.  
  49.         }
  50.         else{
  51.             RadioIntent.putExtra(IS_MALE, false);
  52.             Toast.makeText(getApplicationContext(),"Female Selected",Toast.LENGTH_SHORT).show();
  53.         }
  54.  
  55.         startActivity(RadioIntent);
  56.  
  57.     }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.     public void openResultActivity(){
  67.  
  68.         EditText Hinput = (EditText) findViewById(R.id.heightinput);
  69.         int heightinput = Integer.parseInt(Hinput.getText().toString());
  70.  
  71.         EditText Winput = (EditText) findViewById(R.id.weightinput);
  72.         int weightinput = Integer.parseInt(Winput.getText().toString());
  73.  
  74.  
  75.  
  76.         Intent intent = new Intent(this, ResultActivity.class);
  77.         intent.putExtra(EXTRA_HINPUT, heightinput);
  78.         intent.putExtra(EXTRA_WINPUT, weightinput);
  79.  
  80.  
  81.         startActivity(intent);
  82.  
  83.     }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement