1

有谁知道如何从 webmethod 数组中检索以显示在 listview 上?这是我的网络方法:

[WebMethod]
public info[] retrieveInfo (String code){
SQLCon.. 
.
.
info [] a = new info [count];
cmd.. 
.
.

while(reader.Read()){
    a[i].id = (int)reader["ID"];
    a[i].description = (string)reader["Description"];
    a[i].date = (string)reader["Date"];
    a[i].url = (string)reader["URL"];
    a[i].name = (string)reader["Name"];
    i++
}
reader.Close();
conn.Close();

Array.Reverse(a);
return a;

直到这里,我才设法弄清楚。在那之后我完全迷失了,此外我想把所有的回报都放到listview2中。

//SOAP
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("code", code);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true; // Set this variable to true for
                            // compatibility with what seems to be the default encoding for.Net-Services.

    envelope.setOutputSoapObject(request);

    System.out.println(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
           androidHttpTransport.call(SOAP_ACTION, envelope);
           SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
           Log.i("myApp", response.toString());
           System.out.println("response " +response);

    }catch(SocketException ex)
    {
       Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage());
       ex.printStackTrace();
    }
    catch (Exception e) {
       Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
           e.printStackTrace();

        }
    } 
} 
}
4

1 回答 1

0

我就是这样解决的...

我的 XML 代码是,

<ListView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />

该类应该扩展ListActivity而不是简单的 Activity。

try 块中的代码是,

        SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);    
        SoapSerializationEnvelope soapEnvelop = new     
        SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelop.dotNet=true;
        soapEnvelop.setOutputSoapObject(request);
        HttpTransportSE aht = new HttpTransportSE(URL);
        request.addProperty("authenid",authenid);
            aht.call(SOAP_ACTION, soapEnvelop);     

        SoapObject result;
        result=(SoapObject)soapEnvelop.getResponse();
        int cnt = result.getPropertyCount();
        String[] ary = new String[cnt];

        for(Integer i1=0;i1<cnt;i1++)
        {
            ary[i1]=result.getProperty(i1).toString();

              for(Integer i2=0;i2<=i1;i2++)
                  {
                  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_1, ary);
                    setListAdapter(adapter);
                  } 
        }

希望这可以帮助...

于 2013-03-02T07:59:41.770 回答