我的代码如下:
compile 'io.apisense:rhino-android:1.0'
TextView resultTextView = findViewById(R.id.result_text_view);
String currentText = resultTextView.getText().toString();
boolean valid = checkForValidity();
double result=0;
if(valid){
ScriptEngine engine = new
ScriptEngineManager().getEngineByName("rhino");
try{
result = (double)engine.eval(currentText);
}catch(Exception e){
Toast.makeText(this,"Exception
Raised",Toast.LENGTH_SHORT).show();
}
currentText = currentText +"\n"+ "="+(result);
}
resultTextView.setText(currentText);