1

webmethod 配列から取得してリストビューに表示する方法を知っている人はいますか? これは私のWebメソッドです:

[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クラスは、単純なアクティビティの代わりに拡張する必要があります。

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 に答える