【问题标题】:Retrieve array webmethod into listview Android将数组webmethod检索到listview Android
【发布时间】:2013-01-28 14:04:27
【问题描述】:

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

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

        }
    } 
} 
}

【问题讨论】:

  • 即使我也很想知道这个问题的答案。有什么想法吗??

标签: android arrays web-services android-listview


【解决方案1】:

我就是这样解决的……

我的 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);
                  } 
        }

希望这会有所帮助...

【讨论】:

  • 我希望为此添加评分,并且应该从 web 服务中检索项目...在上面的代码中应该更改哪些代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-12
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多