I created an app that calculates the area and circumference of a circle and then sends the results to the user. The only problem is that I have to place the calculations in a separate class from MainActivity.java. I currently have the calculations at the bottom of the MainActivity.java which is not what I want. Here is what I have so far:
package com.areacircumferencecircle;
import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener {
private Button btn;
private EditText edit;
private TextView area;
private TextView crf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.button1);
edit = (EditText)findViewById(R.id.editText1);
area = (TextView)findViewById(R.id.textArea);
crf = (TextView)findViewById(R.id.textCircumference);
btn.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
if(btn == v){
double r = Double.parseDouble(edit.getText().toString());
String a = Double.toString(3.141592 * (r * r));
String c = Double.toString(2 * 3.141592 * r);
crf.setText("Circumference: " + c);
area.setText("Area: " + a);
}
}
}
Any help is very much appreciated!