How can I pass String value from EditText In Android Activity to Python Script and also make the activity able to retrieve the String result from a function in the python script such as displaying the retrieved String in TextView ?
And my python script is complex script as it needs importing another scripts inside it which one of them connects to sqlite database .
I want to put the scripts in assets folder in Android or in res/raw folder and I don't want the android application to need internet , I want all things embedded in the app .
simple example for this matter is
myscript.py
def addTwoNbrs(x,y):
return x+y
and in android activity
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
}
});
Aucun commentaire:
Enregistrer un commentaire