Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>All right this is lengthy. Take it step by Step</strong></p> <p><strong>1. Create a new class for Web Service Requests:</strong></p> <pre><code>import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import android.content.Context; import android.util.Log; public class WebRequestManager { // YOUR Web Services public static final String LOGIN_METHOD = "///YOUR WEB SERVICE NAME"; // ----------------------------------------------// //----SET BELOW THINGS ACCORDING TO YOUR NEED-----// public static final String NAMESPACE = "http://microsoft.com/webservices/"; public static final String SOAP_ACTION = "http://microsoft.com/webservices/"; public static final String URL = "http://1**.5*.1**.1**/test/WEB_SERVIVE.asmx"; private SoapObject response = null; public WebRequestManager(Context context) { } public void sendRequest(SoapObject requestObj, String methodName) { try { SoapSerializationEnvelope mySoapEnvelop = new SoapSerializationEnvelope( SoapEnvelope.VER11); // request.addProperty("sError", ""); AndroidHttpTransport transport = new AndroidHttpTransport(URL); mySoapEnvelop.setOutputSoapObject(requestObj); mySoapEnvelop.dotNet = true; transport.call(SOAP_ACTION + methodName, mySoapEnvelop); response = getPureResponseObject((SoapObject) mySoapEnvelop.bodyIn); } catch (Exception e) { e.printStackTrace(); } } public SoapObject getResponse() { return this.response; } private SoapObject getPureResponseObject(SoapObject result) { result = (SoapObject) result.getProperty(0); result = (SoapObject) result.getProperty(1); result = (SoapObject) result.getProperty(0); return result; } } </code></pre> <p>** 2. CREATE A BEAN CLASS WITH STRINGS FROM YOUR WEB SERVICE RESPONSE**</p> <pre><code>package com.*.*; public class Customer { String customerTypeId; String customerType; String sDARCustomer; // BEAN CLASS FOR Web service public String getCustomerTypeId() { return customerTypeId; } public void setCustomerTypeId(String customerTypeId) { this.customerTypeId = customerTypeId; } public String getCustomerType() { return customerType; } public void setCustomerType(String customerType) { this.customerType = customerType; } public String getsDARCustomer() { return sDARCustomer; } public void setsDARCustomer(String sDARCustomer) { this.sDARCustomer = sDARCustomer; } } </code></pre> <p><strong>3. CREATE AN INDEPENDENT PARSER CLASS</strong></p> <pre><code>public static ArrayList&lt;BEAN CLASS&gt; parseGetCustomerTypeResponse( SoapObject response) { ArrayList&lt;BEAN CLASS&gt; customerList = new ArrayList&lt;BEAN CLASS&gt;(); for (int count = 0; count &lt; response.getPropertyCount(); count++) { Customer customer = new Customer(); SoapObject records = (SoapObject) response.getProperty(count); // BELOW SET YOUR set METHODS FROM BEAN CLASS customer.setCustomerTypeId(records.getProperty( "YOUR WEB TAG NAME").toString()); customer.setCustomerType(records.getProperty("YOUR WEB SERVICE TAG NAME") .toString()); customerList.add(customer); } return customerList; } </code></pre> <p>** 4. FOLLOWING CODE IN YOUR ACTIVITY. REMEMBER TO CHANGE THINGS IN ACCORDANCE WITH NAMES OF YOUR ADAPTERS AND METHODS **</p> <pre><code>class GetCustomerType extends AsyncTask&lt;String, Void, Integer&gt; { private ProgressDialog progress; @Override protected void onPreExecute() { progress = ProgressDialog.show(GetCustomerTypeActivity.this, "", "Loading ..."); } @Override protected Integer doInBackground(String... params) { try { WebRequestManager requestManager = new WebRequestManager( GetCustomerTypeActivity.this); SoapObject request = new SoapObject( WebRequestManager.NAMESPACE, WebRequestManager.METHOD NAME FROM REQUEST CLASS); requestManager.sendRequest(request, WebRequestManager.METHOD NAME FROM REQUEST CLASS); // DECLARE ARRAYLIST &amp; ARRAYADAPTER OUTSIDE OF ASYNC TASK. IT IS HERE FOR REFERENCE ONLY ArrayList&lt;Customer&gt; custArrList; CustomerArrayAdapter adpater; // BELOW CODE WILL CALL THE PARSER METHOD. CHANGE NAMES ACCORDINGLY custArrList = Parsers .parseGetCustomerTypeResponse(requestManager .getResponse()); return Util.SUCCESS; } catch (Exception e) { e.printStackTrace(); } } protected void onPostExecute(Integer result) { progress.dismiss(); //SET YOUR OWN ADAPTER HERE FOR SPINNER adpater = new CustomerArrayAdapter( GetCustomerTypeActivity.this, R.layout.get_customer_type_imagerow,custArrList); custTypeList.setAdapter(adpater); progress.dismiss(); } } </code></pre> <p><strong>IN THE ACTIVITY PUT THE ADAPTER CODE LIKE BELOW :</strong></p> <pre><code>class CustomerArrayAdapter extends BaseAdapter { private Context context; private int resID; private ArrayList&lt;BEAN CLASS&gt; items; public CustomerArrayAdapter(Context context, int resID, ArrayList&lt;BEAN CLASS&gt; items) { this.context = context; this.resID = resID; this.items = items; } @Override public int getCount() { // TODO Auto-generated method stub return items.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View row, ViewGroup parent) { if (row == null) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(resID, null); } BEAN CLASS item = items.get(position); // THIS IS FOR CUSTOM LISTVIEW. CHANGE NAMES AS NECESSARY TextView custType = (TextView) row .findViewById(R.id.textViewGetCust); custType.setText(item.getCustomerType()); return row; // FOR SPINNER CHANGE ABOVE CODE AS BELOW BEAN CLASS item = items.get(position); TextView text = (TextView) row.findViewById(android.R.id.text1); text.setText(item.getCityName()); text.setTextSize(20); return row; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload