Hi I created a webservice that pulls a list of location names from the database in a array. I need to get this array in a listview on android. I am lost as I am new to android. Please help. Here is the code I have so far. Also I am using a fragment and webservice using soap. Thanks in advance.
public class LocationFragment extends Fragment {
/** Called when the activity is first created. */
TextView tv;
public LocationFragment(){}
private String TAG ="Vik";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_location, container, false);
tv =(TextView)rootView.findViewById(R.id.textView1);
AsyncCallWS task = new AsyncCallWS();
task.execute();
return rootView;
}
private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Log.i(TAG, "doInBackground");
location();
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.i(TAG, "onPostExecute");
}
@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
}
@Override
protected void onProgressUpdate(Void... values) {
Log.i(TAG, "onProgressUpdate");
}
}
public void location()
{
String SOAP_ACTION = "http://example.com/locations";
String METHOD_NAME = "locations";
String NAMESPACE = "http://example.com/";
String URL = "http://100.100.00.80/example/Service.asmx";
try {
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("getlocation", "null");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE transport= new HttpTransportSE(URL);
transport.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
tv.setText("Status : " + resultString);
Log.i(TAG, "Result locations: " + resultString);
}
catch(Exception ex) {
Log.e(TAG, "Error: " + ex.getMessage());
}
}
}