Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. public class TicketFragment extends Fragment {
  2. ListView tv;
  3. public TicketFragment(){}
  4. private String TAG ="Vik";
  5.  
  6. @Override
  7. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  8. Bundle savedInstanceState) {
  9.  
  10. View rootView = inflater.inflate(R.layout.fragment_ticket, container, false);
  11. tv =(ListView)rootView.findViewById(R.id.listView1);
  12.  
  13. AsyncCallWS task = new AsyncCallWS();
  14. task.execute();
  15.  
  16. return rootView;
  17. }
  18.  
  19.  
  20. private class AsyncCallWS extends AsyncTask<Void, Void, Void> {
  21. @Override
  22. protected Void doInBackground(Void... params) {
  23.  
  24. location();
  25. return null;
  26. }
  27.  
  28. @Override
  29. protected void onPostExecute(Void result) {
  30. // Log.i(TAG, "onPostExecute");
  31.  
  32. }
  33.  
  34. @Override
  35. protected void onPreExecute() {
  36. // Log.i(TAG, "onPreExecute");
  37.  
  38. }
  39.  
  40. @Override
  41. protected void onProgressUpdate(Void... values) {
  42. //Log.i(TAG, "onProgressUpdate");
  43. }
  44.  
  45. }
  46.  
  47.  
  48.  
  49.  
  50. public void location()
  51. {
  52. String SOAP_ACTION = "http://example.com/getlocations";
  53. String SOAP_ACTION2 = "http://example.com/getaddress";
  54. String METHOD_NAME = "getlocations";
  55. String METHOD_NAME2 = "getaddress";
  56. String NAMESPACE = "http://example.com/";
  57. String URL = "http://100.100.00.00/example/Service.asmx";
  58.  
  59. try {
  60. SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
  61. SoapObject Request2 = new SoapObject(NAMESPACE, METHOD_NAME2);
  62. SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
  63. SoapEnvelope.VER11);
  64. SoapSerializationEnvelope soapEnvelope2 = new SoapSerializationEnvelope(
  65. SoapEnvelope.VER11);
  66. soapEnvelope.dotNet = true;
  67. soapEnvelope.setOutputSoapObject(Request);
  68. soapEnvelope.setOutputSoapObject(Request2);
  69.  
  70. HttpTransportSE transport= new HttpTransportSE(URL);
  71.  
  72. transport.call(SOAP_ACTION, soapEnvelope);
  73. transport.call(SOAP_ACTION2, soapEnvelope2);
  74.  
  75. SoapObject response = (SoapObject)soapEnvelope.getResponse();
  76. SoapObject response2 = (SoapObject)soapEnvelope2.getResponse();
  77.  
  78. System.out.println(response);
  79. int intPropertyCount = response.getPropertyCount();
  80. String[] locations= new String[intPropertyCount];
  81.  
  82. for (int i = 0; i < intPropertyCount; i++)
  83. {
  84. locations[i] = response.getPropertyAsString(i).toString();
  85.  
  86. }
  87. System.out.println(response2);
  88. int intPropertyCount2 = response2.getPropertyCount();
  89. String[] address= new String[intPropertyCount2];
  90.  
  91. for (int i = 0; i < intPropertyCount; i++)
  92. {
  93. address[i] = response2.getPropertyAsString(i).toString();
  94.  
  95. }
  96.  
  97. final ArrayAdapter<String> adapter =
  98. new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, locations);
  99.  
  100. final ArrayAdapter<String> adapter2 =
  101. new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_2, address);
  102.  
  103. getActivity().runOnUiThread(new Runnable() {
  104. @Override
  105. public void run() {
  106. // This code will always run on the UI thread, therefore is safe to modify UI elements.
  107.  
  108. tv.setAdapter(adapter);
  109. tv.setAdapter(adapter2);
  110. tv.setOnItemClickListener(new OnItemClickListener() {
  111.  
  112. public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
  113. Intent intent = new Intent(getActivity(), CreateTicket.class);
  114. // add data to the intent...
  115. startActivity(intent);
  116. }
  117.  
  118. });
  119.  
  120. }
  121. });
  122. }
  123.  
  124.  
  125. catch(Exception ex) {
  126. Log.e(TAG, "Error: " + ex.getMessage());
  127. }
  128.  
  129. }
  130.  
  131.  
  132. }
  133.  
  134. SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
  135. SoapObject Request2 = new SoapObject(NAMESPACE, METHOD_NAME2);
  136. SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  137. SoapSerializationEnvelope soapEnvelope2 = new SoapSerializationEnvelope(
  138. SoapEnvelope.VER11);
  139. soapEnvelope.dotNet = true;
  140. soapEnvelope.setOutputSoapObject(Request);
  141. soapEnvelope.setOutputSoapObject(Request2); // should be soapEnvelope2.setOutputSoapObject(Request2);
  142.  
  143. <?xml version="1.0" encoding="utf-8"?>
  144. <TextView xmlns:android="http://schemas.android.com/apk/res/android"
  145. android:id="@+id/text1"
  146. android:layout_width="fill_parent"
  147. android:layout_height="wrap_content"
  148. android:textAppearance="?android:attr/textAppearanceLarge"
  149. android:gravity="center_vertical"
  150. android:paddingLeft="6dip"
  151. android:minHeight="?android:attr/listPreferredItemHeight"
  152. />
  153.  
  154. lv.setAdapter(new ArrayAdapter<String>(this,R.layout.custom_layout,R.id.text1,location));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement