从数组列表中获取元素以发出soap请求并获取信息

时间:2016-07-26 20:00:29

标签: java android for-loop arraylist iteration

我想使用ArrayList中的元素来获取所有这些元素的信息并将它们放在listView中。但是当我使用for进行迭代时,我的app块。有人可以告诉我该怎么做以及我的问题在哪里?

活动

import java.text.Da`teFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Timer;  
import java.util.TimerTask;

import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class versistema extends Activity{

private Button btnVersistema;

private TextView sucur3;
private boolean listo = false;
private String id;
private String dia;
private String chocolisto;
private SoapObject idSucur;
private SoapObject namesucur;
private SoapObject eventSucur;
private ListView listSucursales;
String cliente = "";

@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.versistema);

   btnVersistema = (Button) findViewById(R.id.Obsucursales);
   sucur3 = (TextView) findViewById(R.id.Sucur3);
   listSucursales = (ListView)findViewById(R.id.listView1);

   btnVersistema.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            cliente = getIntent().getStringExtra("username");
            AsyncConexion tarea =new AsyncConexion();
            tarea.execute();

//          if(listo = true)
//          {
//              cliente = getIntent().getStringExtra("username");
//              AsyncConexion2 idsucur = new AsyncConexion2();
//              idsucur.execute();
//              
//          }

        }

        });

}

private class AsyncConexion extends AsyncTask<String, Void,Void>
{
    ArrayList<InfoSucursales> sucursalesLi = new ArrayList<InfoSucursales>();
    ArrayList<InfoSucursales> sucursalesId = new ArrayList<InfoSucursales>();
    ArrayList<InfoEventos> eventosScur = new ArrayList<InfoEventos>();
    @Override
    protected Void doInBackground(String... params) {

        namesucur = Obtenersucursales.SucursalesCLiente(cliente);

    if(namesucur.hasProperty("Sucursales")){

        for(int i=0; i<namesucur.getPropertyCount();i++){
            SoapObject resulRem = (SoapObject) namesucur.getProperty(i);
            InfoSucursales nombre = new InfoSucursales();

            if(resulRem.hasProperty("name")){
                nombre.setSucursalname(resulRem.getPropertyAsString("name"));
            }

            sucursalesLi.add(nombre);
    }

    }
    if(sucursalesLi.size() == namesucur.getPropertyCount())
    {
        idSucur = ObtenerIDSucursales.IdSucursales(cliente);


        if(idSucur.hasProperty("IdSucursales")){

            for(int i=0; i<idSucur.getPropertyCount();i++){
                SoapObject resulRem = (SoapObject) idSucur.getProperty(i);
                InfoSucursales id = new InfoSucursales();

                if(resulRem.hasProperty("Id")){
                    id.setSucursalname(resulRem.getPropertyAsString("Id"));
                }

                sucursalesId.add(id);
        }

        }
    }
    if(sucursalesId.size() == idSucur.getPropertyCount())
    {
//      long ahora = System.currentTimeMillis();
//      Date actual = new Date(ahora);
//      DateFormat df = new SimpleDateFormat("yyyy_dd_MM");
//      dia = ("ObjectSignal_"+df.format(actual));

        dia = "ObjectSignal_2016_07_24";

        for(int i=0; i<sucursalesId.size();i++)
        {

        id = sucursalesId.get(i).toString();
        eventSucur = ObtenerEventos.EventosSucur(id,dia);

        if(eventSucur.hasProperty("Eventos")){

                        for(int z=0; z < eventSucur.getPropertyCount(); z++){
                            SoapObject resulRem2 = (SoapObject) eventSucur.getProperty(z);                          InfoEventos Codigo = new InfoEventos();

                        if(resulRem2.hasProperty("Code")){
                                Codigo.setSucursaEvent(resulRem2.getPropertyAsString("Code"));
                            }

                             eventosScur.add(Codigo);

                        }                    
                    }
//          chocolisto =  eventosScur.get( eventosScur.size()-1).toString();
        }
    }


    return null;

    }



    @Override
    protected void onPostExecute(Void result)
    {

//      sucur3.setText(id);
//      CustomListAdapter adapter = new CustomListAdapter(versistema.this,sucursalesLi,chocolisto);
//      listSucursales.setAdapter(adapter);

        ArrayAdapter<InfoEventos> arraysuscur = new ArrayAdapter <InfoEventos>(versistema.this, android.R.layout.simple_list_item_1, eventosScur);
        listSucursales.setAdapter(arraysuscur);
//      

//      ArrayAdapter <InfoSucursales> arraysuscur3 = new ArrayAdapter <InfoSucursales>(versistema.this, android.R.layout.simple_list_item_1,eventosScur);
//      listSucursales.setAdapter(arraysuscur3);

//      listo = true;

    }

}
public class ObtenerEventos {
    final static String NAMESPACE = "http://security_app.org/";
    final static String URL = "http://192.168.1.104:9090/securityapp.asmx";
    final static String METHOD_NAME = "EstadoSucursales";
    final static String SOAP_ACTION = "http://security_app.org/EstadoSucursales";

    public static SoapObject EventosSucur(String id,String dia)
    {
    SoapObject res = null;

    SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);

    request.addProperty("id",id);
    request.addProperty("dia",dia);

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

    HttpTransportSE transporte = new HttpTransportSE(URL);

    try {
        transporte.debug = true;
        transporte.call(SOAP_ACTION, envelope);
        SoapObject response = (SoapObject) envelope.bodyIn;
        SoapObject response2 = (SoapObject) response.getProperty(0);
        SoapObject response3 = (SoapObject) response2.getProperty(1);
        SoapObject response4 = (SoapObject) response3.getProperty(0);

        res = response4;            
    }

    catch (Exception e) {
        e.printStackTrace();
    }

    return res;

    }

}

0 个答案:

没有答案