2012-09-10 63 views
0

您好我必須開發一個使用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幫助我。

+0

您的應用程序真的需要使用基於SOAP的webservice調用來實現此功能嗎? –

+0

是的....必須在這裏使用web服務調用 – user1575906

+0

這不是一個Web服務或ksoap2問題,你問如何將你的Web服務調用的結果分配給列表視圖以及如何爲每個列表項分配一個監聽器打開詳細信息活動。 – Kickaha

回答

0

你有很多事情要處理在這裏。

不要重新分配內容視圖..這是不好的想法。

首先,你需要創建一個適配器照做和鏈接here

然後您需要添加上點擊聽者做here打開新的意圖。

但您的代碼尚未準備好執行此步驟,您首先需要按照上述方式創建適配器。

走開並在此工作,當你準備好後再回來問一個更具體的問題。

Here是一個更具體的答案的問題,你將如何內的點擊監聽器,適配器

0

This打開一個意圖就是一個例子,這將幫助你生成列表視圖和處理其項目單擊。這裏使用的Web服務API是JSON,但您可以看看如何處理服務響應以創建列表視圖並管理它的onclick。讓我知道如果問題仍然存在。

+0

嗨,我知道android listview使用json和xml parsing.but但我想知道調用soap.thanks您的幫助。 – user1575906

+0

我知道你想要什麼,但是你的問題在於如何處理你的列表視圖的onclick,並在下一個活動中顯示相應的數據。無論你使用什麼樣的服務api。我給出的鏈接將幫助你作爲參考。 –