如何将Android活动中的EditText中的String值传递给Python脚本 并且还使活动能够从python脚本中的函数检索String结果 比如在TextView中显示检索到的字符串?
我的python脚本是复杂的脚本,因为它需要在其中导入另一个脚本,其中一个脚本连接到sqlite数据库。
我想将脚本放在Android或res / raw文件夹中的assets文件夹中,我不希望Android应用程序需要互联网,我希望应用程序中嵌入所有内容。
这件事的简单例子是
myscript.py
def addTwoNbrs(x,y):
return x+y
并在android活动中
Button btn = (Button)findViewById(R.id.button1);
final EditText et1 = (EditText)findViewById(R.id.editText1);
final EditText et2 = (EditText)findViewById(R.id.editText2);
final TextView result = (TextView)findViewById(R.id.textView1);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
int x = new Integer(et1.getText().toString());
int y = new Integer(et2.getText().toString());
// How to call python script with these 2 parameters x , y to calculate
int z= // return the result from the script
}
});