I am new to android. This question is a phase from my steps in experimenting with android apps and web service. I have asked a question before, which is in here: Fail to connect android to web service. Below is my Updated code, my code in MainActivity:
public class MainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
Mytask mt = new Mytask();
mt.execute();
}
}
my code in Mytask:
public class Mytask extends AsyncTask<String, Integer, String> {
private static final String SOAP_ACTION = "http://services.aonaware.com/webservices/Define";
private static final String URL = "http://services.aonaware.com/DictService/DictService.asmx";
private static final String METHOD_NAME = "Define";
private static final String NAMESPACE = "http://services.aonaware.com/webservices/";
String resultData=null;
@Override
protected String doInBackground(String... params) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo property = new PropertyInfo();
property.setName("word");
property.setType(String.class);
property.setValue("computer");
request.addProperty(property);
Log.i("soap tobe", "----");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
Object response = null;
try {
androidHttpTransport.getServiceConnection();
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
Log.i("soap passed", "----"+response);
response = envelope.getResponse();
resultData= response.toString();
} catch (Exception e) {
e.printStackTrace();
}
Log.i("result passed", "----"+response.toString());
return resultData;
}
protected void onPostExecute(String result) {
Log.i("onPost passed", "----"+result);
}
}
I got the result right in the "onPost passed" log. From here, how can I put the result into TextView in MainActivity?
You need to use interface
1.) Create interface class in your asyncTask class.
2.) And declare interface AsyncResponse as a field in asyncTask class:
3.) In your main Activity you need to implements interface AsyncResponse.
Edit
And activity code