12870

android listview using soap calling

Question:

Hi i have to develop one listview app in android using soap calling.here i wish to run the app means the orderid and status is displayed here.here i have to click any order from list means the status is displayed next activity.

But the orderid and status is displayed on listview successfully..but here faced some problem...the orderid and status is displayed following format:

1 --------- F2 ---------- Q3 ---------- P -----------

But i wish to display below format:

1 F --------- 2 Q --------- 3 P ---------

This is my <strong>android code</strong>:

public class RetailerActivity extends Activity { ListView list; private static final String SOAP_ACTION = "http://xcart.com/customerData1"; private static final String METHOD_NAME = "customerData1"; private static final String NAMESPACE = "http://xcart.com"; private static final String URL = "http://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl"; private static final String KEY_STATUS = "status"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransportSE ht = new HttpTransportSE(URL); try { ht.call(SOAP_ACTION, envelope); SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); SoapPrimitive s = response; String str = s.toString(); String resultArr[] = str.split("&"); list=(ListView)findViewById(R.id.list); list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,resultArr)); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String s2= getIntent().getStringExtra("status"); // Starting new intent Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class); in.putExtra(KEY_STATUS, s2); startActivity(in); } }); } catch (Exception e) { e.printStackTrace(); } } }

This is my <strong>webservice code</strong>:

public class RetailerWs { public String customerData1(){ String customerInfo = ""; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root",""); //Find customer information where the customer ID is maximum PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_orders"); ResultSet result = statement.executeQuery(); while(result.next()){ customerInfo = customerInfo + result.getString("orderid") + "&" + result.getString("status"); //Here "&"s are added to the return string. This is help to split the string in Android application } } catch(Exception exc){ System.out.println(exc.getMessage()); } return customerInfo; } }

this is my main.xml file:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="#b5b5b5" android:dividerHeight="1dp" android:listSelector="@drawable/list_selector" /> </LinearLayout>

Answer1:

Change your webservice code line:

customerInfo = customerInfo + result.getString("orderid") + "&" + result.getString("status");

to:

customerInfo = customerInfo + result.getString("orderid") + " " // this to separate order id from status + result.getString("status") + "&" ; // this is where you split in your android code

So, for your sample input

1 F 2 Q 3 P

you now generate the string "1 F&2 Q&3 P" instead of "1&F2&Q3&P".

After that, I suggest you to think some better way to pass data between your components.

Answer2:

You can Use XML Like this-- Try this Does it work for u

main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#FFFFFF" android:height="1sp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:height="1sp" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:paddingRight="2px"> <ListView android:id="@+id/android:list" android:fadingEdge="none" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0" /> </LinearLayout> </LinearLayout>

List View To Fill You Data -- it has the same size u want for your layout

<?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lv" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="#000000"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> <TextView android:id="@+id/orderid" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="left"/> <TextView android:id="@+id/Status" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="left"/> <TextView android:id="@+id/Status" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="right"/> <TextView android:id="@+id/Status" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="right"/> <TextView android:id="@+id/Status" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="right"/> <TextView android:id="@+id/Status" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="right"/> <TextView android:id="@+id/Status" android:textColor="#7E3517" android:typeface="sans" android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="1.0" android:width="1dip" android:gravity="right"/> </LinearLayout> </LinearLayout>

Recommend

  • Android accesing soap service
  • kSOAP2 communication with webservices C#
  • ksoap2 - request parameters is set null
  • Android webservice access error
  • Android: Parsing XML with KSOAP
  • Make synchronous Http/REST call in WP7?
  • Copy Access database query into Excel spreadsheet
  • How do I resolve an “invalid quantifier” error with regexp in javascript?
  • SOAP web service with ksoap2 lib
  • Java.net.SocketTimeoutException in Ksoap2
  • getting Json result in Android
  • Guzzle Error with Laravel. ClientException in RequestException.php line 107:
  • RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  • How to use HTTP Authentication with PHP and then run the entered data against a database?
  • Update Search Results to Lazy Adapter in android
  • Why does .addView throw this parent/child exception?
  • Eventbus onMessageEvent not getting called
  • How to Handle Click on Imageview in Custom Listview with image and Textview?
  • Android: How do you create an EditText field in java class
  • CloseOptionsMenu doesn't work?
  • Unable to resolve Static method?
  • How to Save JSON data to SQL server database in C#?
  • How to estimate the Kalman Filter with 'KFAS' R package, with an AR(1) transition equation
  • Parse a date string in a specific locale (not timezone!)
  • How to handle AllServersUnavailable Exception
  • Rearranging Cells in UITableView Bug & Saving Changes
  • 0x202A in filename: Why?
  • Circular dependency while pushing http interceptor
  • Is there a mandatory requirement to switch app.yaml?
  • Linker errors when using intrinsic function via function pointer
  • File upload with ng-file-upload throwing error
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • AngularJs get employee from factory
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Change div Background jquery
  • How to stop GridView from loading again when I press back button?
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases
  • Why do underscore prefixed variables exist?