0

我试图通过soap调用从mysql数据库中检索数据。

这里面临以下问题。

我使用了以下网络服务代码:

 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") 
            + " "   // this to separate order id from status
            + result.getString("status") 
            + " " 
            + result.getString("payment_method") 
            + " " 
            + result.getString("total") 
            + " " 
    // this to separate order id from status
                    + result.getString("login") 
                    + "&" ;
  }}
  catch(Exception exc){
  System.out.println(exc.getMessage());
  }

  return customerInfo;
  }}

这是我的安卓代码:

 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";
 @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);

 // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
 //R.layout.list_row, R.id.orderid);
 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();
 }
 }

 }

这是我目前的 o/p在此处输入图像描述

但我希望需要如下格式的 o/p:

1            P         399.99
Krishna
Check(manual processing)
------------------------------
2            P         314.65
Krishna
Phone Ordering
------------------------------

请帮助我..我该如何开发这个。

4

1 回答 1

0

您可以通过创建 2 个 xml 来执行此操作

第一个 xml 将定义您的列表视图的听众和您要填写的数据列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#EFEFF7"
android:layout_width="fill_parent" android:layout_height="fill_parent"  android:orientation="vertical">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
    android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
        <TextView android:text="ID" android:width="120dip"   android:layout_width="wrap_content"
        android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
        android:height="25sp" />
        <TextView android:text="Name" android:layout_weight="1.0"   android:layout_width="wrap_content"
        android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
        android:height="25sp" />
        <TextView android:text="Money ($)" android:width="80dip"  android:layout_width="wrap_content"
        android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
        android:height="25sp" />
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:background="#000000" 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="#000000">
        <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1.0" />
    </LinearLayout>
</LinearLayout>

和 ListView 这是第一个 xml 可以在其他其他 xml 中定义您在 ListView 中需要哪些项目

<?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:background="#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="#000000">
    <TextView android:id="@+id/ID" android:textColor="#FFFFFF" android:typeface="sans"
    android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
    android:width="120dip" /> //Can use this ID to display ID for Example 1

    <TextView android:id="@+id/Name" android:textColor="#FFFFFF" android:typeface="sans"
    android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
    android:layout_weight="1.0" /> //Can use this ID to display Name Like P

    <TextView android:id="@+id/Money" android:textColor="#FFFFFF" android:typeface="sans"
    android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
    android:width="80dip" /> //Can use this ID to display Money like 300 $

</LinearLayout>

<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="#EFEFF7">
    <TextView android:textSize="20sp" android:text="Namee  of person " android:textColor="#000000" android:typeface="sans"
    android:layout_height="fill_parent" android:layout_width="wrap_content"
    android:width="90dip" /> // you display krishna through this ID 

</LinearLayout>


<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="#EFEFF7">
    <TextView android:textSize="20sp" android:text="Namee  of person " android:textColor="#000000" android:typeface="sans"
    android:layout_height="fill_parent" android:layout_width="wrap_content"
    android:width="90dip" /> // you display phone ordering through this ID 

    </LinearLayout>
</LinearLayout>
于 2012-10-27T07:23:15.070 回答