2012-09-18 37 views
0

嗨,我必须在android中使用soap calls.here开发一个listview应用程序,我希望运行应用程序意味着orderid和状态显示here.here我必须单击列表中的任何顺序意味着状态显示下一个活动。Android的ListView使用肥皂呼吁

但OrderID和状态显示在列表视图successfully..but这里遇到了一些问题...... OrderID和状态显示格式如下:

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

但我希望以显示如下格式:

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

这是我的Android代码

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(); 
    } 
} 

} 

这是我web服务代码

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; 
} 

} 

这是我的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"> 

<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> 

回答

0

更改您的Web服务代码行:

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

到:

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

所以,为您的样品输入

1 F 
2 Q 
3 P 

你现在生成的条纹g“1 F & 2 Q & 3 P”而不是“1 & F2 & Q3 & P”。

之后,我建议你想一些更好的方法来在你的组件之间传递数据。

+0

这对我来说真的很有帮助 – user1676640

0

您可以使用XML就像this--试试这是否是工作ü

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 F虐待你的数据 - 它有ü要为你的布局相同大小

<?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> 
+0

请参阅我的更新问题 – user1676640

+0

您也可以使用摘要适配器来存档您的列表查看 –