0

我是 android 的新手。我有一个字符串响应,我需要在 spinner 中显示。我已经发送了响应..

04-12 16:15:44.567: I/System.out(9569): Json obj length:: 58
04-12 16:15:44.577: I/System.out(9569): Alabama
04-12 16:15:44.577: I/System.out(9569): Alaska
04-12 16:15:44.577: I/System.out(9569): Alberta
04-12 16:15:44.577: I/System.out(9569): Arizona
04-12 16:15:44.597: I/System.out(9569): Arkansas
04-12 16:15:44.597: I/System.out(9569): British Colombia
04-12 16:15:44.597: I/System.out(9569): California
04-12 16:15:44.597: I/System.out(9569): Colorado
04-12 16:15:44.597: I/System.out(9569): Connecticut
04-12 16:15:44.597: I/System.out(9569): Delaware
04-12 16:15:44.597: I/System.out(9569): District Of Columbia
04-12 16:15:44.597: I/System.out(9569): Florida
04-12 16:15:44.597: I/System.out(9569): Georgia
04-12 16:15:44.597: I/System.out(9569): Hawaii
04-12 16:15:44.597: I/System.out(9569): Idaho
04-12 16:15:44.597: I/System.out(9569): Illinois
04-12 16:15:44.597: I/System.out(9569): Indiana
04-12 16:15:44.607: I/System.out(9569): Iowa
04-12 16:15:44.607: I/System.out(9569): Kansas
04-12 16:15:44.607: I/System.out(9569): Kentucky
04-12 16:15:44.607: I/System.out(9569): London
04-12 16:15:44.607: I/System.out(9569): Louisiana
04-12 16:15:44.607: I/System.out(9569): Maine
04-12 16:15:44.607: I/System.out(9569): Maryland
04-12 16:15:44.607: I/System.out(9569): Massachusetts
04-12 16:15:44.607: I/System.out(9569): Michigan
04-12 16:15:44.607: I/System.out(9569): Minnesota
04-12 16:15:44.618: I/System.out(9569): Mississippi
04-12 16:15:44.618: I/System.out(9569): Missouri
04-12 16:15:44.618: I/System.out(9569): Montana
04-12 16:15:44.618: I/System.out(9569): Nebraska
04-12 16:15:44.618: I/System.out(9569): Nevada
04-12 16:15:44.618: I/System.out(9569): New Hampshire
04-12 16:15:44.618: I/System.out(9569): New Jersey
04-12 16:15:44.618: I/System.out(9569): New Mexico
04-12 16:15:44.618: I/System.out(9569): New York
04-12 16:15:44.618: I/System.out(9569): North Carolina
04-12 16:15:44.628: I/System.out(9569): North Dakota
04-12 16:15:44.628: I/System.out(9569): Ohio
04-12 16:15:44.628: I/System.out(9569): Oklahoma
04-12 16:15:44.628: I/System.out(9569): Ontario
04-12 16:15:44.628: I/System.out(9569): Oregon
04-12 16:15:44.628: I/System.out(9569): Pennsylvania
04-12 16:15:44.628: I/System.out(9569): Puerto Rico
04-12 16:15:44.628: I/System.out(9569): Quebec
04-12 16:15:44.638: I/System.out(9569): Rhode Island
04-12 16:15:44.648: I/System.out(9569): South Carolina
04-12 16:15:44.648: I/System.out(9569): South Dakota
04-12 16:15:44.648: I/System.out(9569): Tennessee
04-12 16:15:44.648: I/System.out(9569): Texas
04-12 16:15:44.648: I/System.out(9569): Utah
04-12 16:15:44.648: I/System.out(9569): Vermont
04-12 16:15:44.648: I/System.out(9569): Virgin Island
04-12 16:15:44.658: I/System.out(9569): Virginia
04-12 16:15:44.658: I/System.out(9569): Washington
04-12 16:15:44.658: I/System.out(9569): West Virginia
04-12 16:15:44.658: I/System.out(9569): Wisconsin
04-12 16:15:44.658: I/System.out(9569): Wyoming

我的代码是

public  ArrayList<TourScheduleInfo> GetCustomerState(String stateName) {



        SoapObject soap_request = new SoapObject(DataMemeber.NAMESPACE, DataMemeber.CUSTOMER_STATE_METHOD_NAME);


        SoapSerializationEnvelope envelope_order = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope_order.dotNet = true;
        envelope_order.setOutputSoapObject(soap_request);
        HttpTransportSE androidHttpTransports = new HttpTransportSE(DataMemeber.URL);
        try 
        {
            String SOAP_ACT = DataMemeber.NAMESPACE + DataMemeber.CUSTOMER_STATE_METHOD_NAME;
            System.out.println("SOAP_ACT IN OrderNo:: " + SOAP_ACT);

            androidHttpTransports.call(SOAP_ACT, envelope_order);
            Object response = envelope_order.getResponse();
            System.out.println("Input String :: " + envelope_order.bodyOut);
            Log.i("Output: ", response.toString());




           JSONArray jsonobj = new JSONArray(response.toString());
            System.out.println("Json obj length:: " + jsonobj.length());
             for(int i=0; i<jsonobj.length(); i++)
            {
                TourScheduleInfo tourInfo = new TourScheduleInfo();

                JSONObject jobj = jsonobj.getJSONObject(i);
                stateName = jobj.getString("StateName");


                tourInfo.setStateName(stateName);

                System.out.println(stateName);

                StatenameList.add(tourInfo);
                tourInfo.getStateName();

          }

             System.out.println(StatenameList);
        } 
        catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception :: " + e.toString());
        }

        return StatenameList;
    }

我必须在另一个类中设置微调器值。所以我必须获取数组值并传递给另一个类中的微调器。我尝试了很多方法,但没有得到帮助。

4

1 回答 1

0

将响应字符串放入数组

ArrayList<String> mArrayList = new ArrayList<String>();

        ............
        androidHttpTransports.call(SOAP_ACT, envelope_order);
        Object response = envelope_order.getResponse();
        System.out.println("Input String :: " + envelope_order.bodyOut);
        Log.i("Output: ", response.toString());

        mArrayList.add( response.toString());   //here you put your data to array
       .......

并执行以下操作..

Spinner s = (Spinner) findViewById(R.id.spin);  //Spinner its id is spin
 ArrayAdapter adapter = new ArrayAdapter(this,
 android.R.layout.simple_spinner_item, mArrayList );
 s.setAdapter(adapter);
于 2012-04-12T10:56:32.763 回答