メインクラスがアクティビティで拡張され、その内部で asynctask で拡張される内部クラスが定義されていますが、内部クラスでは TextView.setText("Hi) を使用しましたが、表示されません。
public class MainActivity extends Activity
{
TextView tv;
String s;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mytask m=new mytask(s);
//Log.d("String1",s);
//tv.setText("Hi");
m.execute();
}
public class mytask extends AsyncTask<String, Void, String>
{
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "HelloWorld";
private static final String URL = "http://10.0.2.2:1070/HelloWorld/WebService.asmx?wsdl";
String k;
public mytask(String s)
{
k=s;
}
// @SuppressWarnings("unused")
protected String doInBackground(String... params)
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
tv=(TextView)findViewById(R.id.text_view);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
Log.d("Envelope", envelope.toString());
try
{
Log.d("res", "entered");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
//this is the actual part thnteredat will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
//responce=
Log.d("res1", result.toString());
if(result != null)
{
s=result.getPropertyAsString(0).toString();
Log.d("string", s);
tv.setText("Hi");
//Get the first property and change the label text
}
else
{
Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
}
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}