Guest User

Untitled

a guest
Jun 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package ring_ring.cal;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10.  
  11. public class Main extends Activity {
  12.  
  13. @SuppressWarnings("unchecked")
  14. public <T> T findViewById(Class<T> t, int id) {
  15. return (T) findViewById(id);
  16. }
  17.  
  18. @Override
  19. public void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.main);
  22.  
  23. Button button = (Button) findViewById(R.id.add);
  24. button.setOnClickListener(new OnClickListener() {
  25. public void onClick(View v) {
  26. double x = Double.parseDouble(findViewById(EditText.class,
  27. R.id.x).getText().toString());
  28. double y = Double.parseDouble(findViewById(EditText.class,
  29. R.id.y).getText().toString());
  30.  
  31. findViewById(TextView.class, R.id.result).setText("" + (x + y));
  32. }
  33. });
  34. }
  35. }
Add Comment
Please, Sign In to add comment