public
Last active

Mashape Android Async example

  • Download Gist
mashapeandroidsnippet.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
public void sendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
new CallMashapeAsync().execute(message);
}
private class CallMashapeAsync extends AsyncTask<String, Integer, MashapeResponse<JSONObject>> {
protected MashapeResponse<JSONObject> doInBackground(String... msg) {
QuestionAnswering client = new QuestionAnswering("MASHAPE_KEY");
return client.answerAQuestion(msg[0]);
}
protected void onProgressUpdate(Integer...integers) {
}
protected void onPostExecute(MashapeResponse<JSONObject> response) {
String answer = response.getBody().toString();
TextView txtView = (TextView) findViewById(R.id.textView1);
txtView.setText(answer);
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.