Created
January 18, 2012 22:38
-
-
Save bkase/1636273 to your computer and use it in GitHub Desktop.
CircleTimeActivity from mobile apps club
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.cmu.mobileappsclub.circletime; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
public class CircleTimeActivity extends Activity { | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Button areaButton = (Button) this.findViewById(R.id.areaButton); | |
areaButton.setOnClickListener(new AreaListener()); | |
Button clearButton = (Button) this.findViewById(R.id.clearButton); | |
clearButton.setOnClickListener(new OnClickListener() { | |
public void onClick(View arg0) { | |
// TODO Auto-generated method stub | |
EditText input = (EditText) CircleTimeActivity.this.findViewById(R.id.textbox); | |
input.setText(""); | |
Log.d("clear", "We pressed the clear button"); | |
} | |
}); | |
} | |
private class AreaListener implements OnClickListener { | |
public void onClick(View arg0) { | |
// TODO Auto-generated method stub | |
EditText input = (EditText) CircleTimeActivity.this.findViewById(R.id.textbox); | |
double radius = Double.parseDouble(input.getEditableText().toString()); | |
double area = radius*radius*Math.PI; | |
Toast.makeText(CircleTimeActivity.this, "The area of the circle is " + area, Toast.LENGTH_LONG).show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment