您好我必須開發一個使用soap調用listview。我希望實現一步..我必須點擊任何列表意味着詳細說明顯示到下一個activity.how我可以開發this.please幫助我..使用肥皂呼叫在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";
/** 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("&");//Result string will split & store in an array
list=(ListView)findViewById(R.id.list);
TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
setContentView(tv);
} 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;
}
}
現在我已經運行應用程序意味着OrderID和狀態fetche D從數據庫和顯示在我的Android應用程序。我希望實現我必須點擊無論訂單意味着訂單狀態顯示下activity.how我可以開發this.please幫助我。
您的應用程序真的需要使用基於SOAP的webservice調用來實現此功能嗎? –
是的....必須在這裏使用web服務調用 – user1575906
這不是一個Web服務或ksoap2問題,你問如何將你的Web服務調用的結果分配給列表視圖以及如何爲每個列表項分配一個監聽器打開詳細信息活動。 – Kickaha