I am creating an application where you would input your height and weight, compute the bmi then click the next button to go to another class and display the bmi result on a fragment within the class.I want to know why it stops after clicking the button. Here is my code:
package com.example.hcon;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class FirstActivity extends Activity {
Button button1;
EditText et_name;
EditText et_height;
EditText et_weight;
double ht = 0;
double wt = 0;
TextView bmiOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
et_name = (EditText) findViewById(R.id.et_name);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
et_height = (EditText) findViewById(R.id.et_height);
et_weight = (EditText) findViewById(R.id.et_weight);
ht = Double.parseDouble(et_height.getText().toString());
wt = Double.parseDouble(et_weight.getText().toString());
double bmi = wt / (ht * ht);
Intent a = new Intent(FirstActivity.this, SecActivity.class);
a.putExtra(out, out);
Toast.makeText(FirstActivity.this, "Welcome " + et_name.getText().toString(), Toast.LENGTH_LONG).show();
startActivity(new Intent(FirstActivity.this, SecActivity.class));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.first, menu);
return true;
}
}
SecActivity.class is the activity containing the fragment where the output should be displayed.