WEB开发网
开发学院手机开发Android 开发 Android 中利用反射技术实现加减乘除 阅读

Android 中利用反射技术实现加减乘除

 2010-08-17 11:00:00 来源:WEB开发网   
核心提示:int first, second;String operaionFun = "";/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {s

int first, second;

String operaionFun = "";

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

findview();

add.setOnClickListener(click);

cut.setOnClickListener(click);

ride.setOnClickListener(click);

Except.setOnClickListener(click);

sum.setOnClickListener(click);

}

void findview() {

one = (EditText) findViewById(R.id.EditText01);

two = (EditText) findViewById(R.id.EditText02);

result = (TextView) findViewById(R.id.TextView01);

add = (Button) findViewById(R.id.Button01);

cut = (Button) findViewById(R.id.Button02);

ride = (Button) findViewById(R.id.Button03);

Except = (Button) findViewById(R.id.Button04);

sum = (Button) findViewById(R.id.Button05);

}

OnClickListener click = new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

first = Integer.parseInt(one.getText().toString());

second = Integer.parseInt(two.getText().toString());

switch (v.getId()) {

case R.id.Button01:

operaionFun = "+";

break;

case R.id.Button02:

operaionFun = "-";

break;

case R.id.Button03:

operaionFun = "*";

break;

case R.id.Button04:

operaionFun = "/";

break;

case R.id.Button05:

try {

result.setText(operation(operaionFun, first, second));

} catch (SecurityException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalArgumentException e) {

上一页  1 2 3 4 5 6  下一页

Tags:Android 利用 反射

编辑录入:coldstar [复制链接] [打 印]
赞助商链接