我想在计算器中进行多项操作,例如:2+3*3/7
. 怎么做。谁能帮我。计算器工作的单一操作。
如何一次计算多个操作editText
。此代码添加在相等按钮单击方法上。
下面是我的代码:
btnEqualto.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String str2 = edtxt.getText().toString();
if (buttonPressed.equals("+"))
{
Log.e(TAG,"dot operation="+strDot);
if (strDot.equals("."))
{
Log.e(TAG, "If Codition :");
String str1[] = str2.split("[+]");
Log.e(TAG,"str1 ="+str1);
String strVal11 = str1[0];
String strVal22 = str1[1];
Log.e(TAG, "strValues :" + strVal11 + " & " + strVal22);
Double xx = Double.parseDouble(strVal11);
Double yy = Double.parseDouble(strVal22);
Log.e(TAG, "Value of x :" + xx + " AND y : " + yy);
Log.e(TAG, "dot operation");
Double result = xx + yy;
Log.e(TAG, "Result :" + result);
edtxt.setText(result + "");
Log.e(TAG, "VAlue of Result :" + edtxt);
}
else
{
Log.e(TAG, "If Codition :"+strVal2);
strDot = "";
String str1[] = str2.split("[+]");
strVal1 = str1[0];
strVal2 = str1[1];
Log.e(TAG, "Esle Condition 4 Pllus strValues :" + strVal1 + " & " + strVal2);
x = Integer.parseInt(strVal1);
y = Integer.parseInt(strVal2);
Log.e(TAG, "Value of x :" + x + " AND y : " + y);
int result = x + y;
Log.e(TAG, "Result :" + result);
edtxt.setText(result + "");
Log.e(TAG, "VAlue of Result :" + edtxt);
}
}
}
}
);