0

Web サービスを消費して応答を解析する asynctask クラスがあります。解析後、list<> を取得しています。どうすれば他のクラスに渡すことができますか?.

ここに私の非同期タスククラスがあります

String response;
    List<Item> lstresponse_locations = null;
//  CustomAdapter CustAdapter;
//  List<Item> lstresult = new ArrayList<Item>();
//  ListView lstcities;



//  String params;
    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub\

        SendRequesttoServer(params);
        return response;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);


    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
    }

// getting response from webservice

    public void SendRequesttoServer(String[] params) {

        try {

        SOAP_ACTION = NAMESPACE + METHOD;
        SoapObject request = new SoapObject(NAMESPACE, METHOD);
        request.addProperty("CityName", params[0]);

        SoapSerializationEnvelope res = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
        res.dotNet = true;
        res.setOutputSoapObject(request);

        HttpTransportSE call = new HttpTransportSE(url);

        SoapPrimitive result;
        call.call(SOAP_ACTION, res);
        result = (SoapPrimitive) res.getResponse();
        ParseLocations Objparselocations = new ParseLocations(
                    new ByteArrayInputStream(result.toString()
                            .getBytes("UTF-8")));
        lstresponse_locations = Objparselocations.parse();

        response = lstresponse_locations.toString();
            // lstCities.toArray();

        System.out.println(lstresponse);
    } catch (SoapFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
}

どうすれば応答を渡すことができますか? ありがとうラム

4

3 に答える 3

0

アクティビティ自体で onPostExecute をオーバーライドし、onPostExecute 内にアダプター オブジェクトを作成し、アダプターを次のようにリストビューに設定してみてください。

Class MyActivity extends Activity {

    public void onCreate(Bundle args) {
     ......
     ......
     new MyAsyncTask() {

       public void onPostExecute(List<Object> list) {
          listView.setAdapter(new MyAdapter(list));
       }

     }.execute(params);
     .......
     ........
   }
}

編集: AsyncTask クラスで、3 番目のパラメーターを List のようにします。

class MyAsync extends AsycnTask<String, Integer, List<Object>>
于 2013-03-08T10:59:30.853 に答える
0

あなたListViewとそのコンストラクターに渡して、メソッドに設定するAdapterだけです。私のためにうまくいったAsyncTaskAdapteronPostExecute()

于 2013-03-08T11:00:08.260 に答える
0

doInBackground から post execute に文字列が返されるため、postExceute の結果が応答になります。

  protected void onPostExecute(String result) {
                // TODO Auto-generated method stub
                super.onPostExecute(result);
Log.d("Response: ",result);

}
于 2013-03-08T10:30:29.927 に答える