package com.example.aaa;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener((OnCheckedChangeListener) 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;
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
EditText et1 = (EditText) findViewById(R.id.num1);
EditText et2 = (EditText) findViewById(R.id.num2);
String s1 = et1.getText().toString();
String s2 = et2.getText().toString();
double a1 = Integer.valueOf(s1).intValue();
double a2 = Integer.valueOf(s2).intValue();
// TODO 自动生成的方法存根
TextView tv = (TextView) findViewById(R.id.Text);
switch (checkedId) {
case R.id.add:
a1 = a1 + a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
case R.id.min:
a1 = a1 - a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
case R.id.mul:
a1 = a1 * a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
case R.id.dev:
a1 = a1 / a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
}
}
public void click(View view) {
TextView tv = (TextView) findViewById(R.id.Text);
TextView tv2 = (TextView) findViewById(R.id.num2);
;
TextView tv3 = (TextView) findViewById(R.id.num1);
;
switch (view.getId()) {
case R.id.button1:
tv.setText("");
tv2.setText("");
tv3.setText("");
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
rg.setOnCheckedChangeListener((OnCheckedChangeListener) 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;
}
public void onCheckedChanged(RadioGroup group, int checkedId) {
EditText et1 = (EditText) findViewById(R.id.num1);
EditText et2 = (EditText) findViewById(R.id.num2);
String s1 = et1.getText().toString();
String s2 = et2.getText().toString();
double a1 = Integer.valueOf(s1).intValue();
double a2 = Integer.valueOf(s2).intValue();
// TODO 自动生成的方法存根
TextView tv = (TextView) findViewById(R.id.Text);
switch (checkedId) {
case R.id.add:
a1 = a1 + a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
case R.id.min:
a1 = a1 - a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
case R.id.mul:
a1 = a1 * a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
case R.id.dev:
a1 = a1 / a2;
s1 = String.valueOf(a1);
tv.setText(s1);
break;
}
}
public void click(View view) {
TextView tv = (TextView) findViewById(R.id.Text);
TextView tv2 = (TextView) findViewById(R.id.num2);
;
TextView tv3 = (TextView) findViewById(R.id.num1);
;
switch (view.getId()) {
case R.id.button1:
tv.setText("");
tv2.setText("");
tv3.setText("");
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}