spinner 下拉運算選項,簡單計算器問題
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String[] lan = getResources().getStringArray(R.array.signed);
Toast.makeText(MainActivity.this, "你選擇的是: " + lan[arg2],?
Toast.LENGTH_LONG).show();
}
******
public void CalcStart(View v) {
? ? Log.d("TAG", "CalcStart()");
? ?
? ? EditText num1Edit = (EditText) findViewById(R.id.num1EDIT);
? ? String strNum1 = num1Edit.getText().toString();
? ? int num1 = Integer.parseInt(strNum1);
? ?
? ? EditText num2Edit = (EditText) findViewById(R.id.num2EDIT);
? ? String strNum2 = num2Edit.getText().toString();
? ? int num2 = Integer.parseInt(strNum2);
? ? if ( 這里應該怎么調用.equals("+") ){
? ? int result = num1 + num2;
? ? }
? ? else if ( ){
? ? int result = num1 * num2;
? ? }
? ? else if (){
? ? int result = num1 - num2;
? ? }
? ? else if(){
? ? int result = num1 / num2;
? ? }
? ? int result = num1 * num2;
? ? TextView resultText = (TextView) findViewById(R.id.resultTXT);
? ? resultText.setText("= " + result);
? ?
? ? }
2016-05-16
需要判斷用戶輸入了什么符號,然后利用indexof來做截取那個符號,保存到一個變量里,if判斷那個變量就好
2016-03-28
怎么調用判斷選項是加減還是乘除