Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ring_ring.cal;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class Main extends Activity {
- @SuppressWarnings("unchecked")
- public <T> T findViewById(Class<T> t, int id) {
- return (T) findViewById(id);
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button button = (Button) findViewById(R.id.add);
- button.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- double x = Double.parseDouble(findViewById(EditText.class,
- R.id.x).getText().toString());
- double y = Double.parseDouble(findViewById(EditText.class,
- R.id.y).getText().toString());
- findViewById(TextView.class, R.id.result).setText("" + (x + y));
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment