Pepe Ballaga
unread,May 9, 2017, 1:07:07 PM5/9/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to desarrolladores-android
Holaa amigos deseo hacer una aplicacion que lea de un webservice de
manera asincronica datos de tipo ArrayList<HashMap<String, String>>..
he encontrado algunos ejemplos en internet, pero me dan error. Por
favor si tienes algun ejemplo completo te agradeceria me lo enviaras.
Saludos
PEPE
Este es mi ejemplo y me error en el momento de conectarse al
webservice...curioso pues si cambio el tipo de datos a
ArrayList<String> pues funciona perfectamente
public class MainActivity extends AppCompatActivity {
private String NAMESPACE, URL,METHOD_NAME, SOAP_ACTION ="";
SoapObject fila, filas;
//List<String> arraylist = new ArrayList<String>();
ArrayList<HashMap<String, String>> list;
public static final String FIRST_COLUMN="First";
public static final String SECOND_COLUMN="Second";
public static final String THIRD_COLUMN="Third";
public static final String FOURTH_COLUMN="Fourth";
//private ArrayList<HashMap> list;
//ArrayList<HashMap> arraylist ;
ArrayAdapter<String> arrayadapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NAMESPACE = Helper.getConfigValue(this,"NAMESPACE");
URL = Helper.getConfigValue(this, "URL");
METHOD_NAME = "Unidades";
SOAP_ACTION = NAMESPACE+METHOD_NAME;
//SOAP_ACTION = URL+METHOD_NAME;
filas=null;
String URL="";
Dowork task = new Dowork();
ArrayList<HashMap<String, String>> arr; // = new
ArrayList<HashMap<String, String>>();
task.execute();
ListView listView=(ListView)findViewById(R.id.listView1);
}
public class Dowork extends AsyncTask<String, Void,
ArrayList<HashMap<String, String>>> {
private final ProgressDialog dialogue = new
ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
this.dialogue.setMessage("Conectando...");
this.dialogue.show();
}
@Override
protected void onCancelled() {
super.onCancelled();
}
@Override
protected void onPostExecute( ArrayList<HashMap<String,
String>> listica) {
ListView listView=(ListView)findViewById(R.id.listView1);
//aca debo obtener el arreglo devuelto
if (listica.isEmpty() )
{
}
if (this.dialogue.isShowing()) {
this.dialogue.dismiss();
}
}
@Override
protected ArrayList<HashMap<String,String>>
doInBackground(String ...params) {
SoapObject request = new SoapObject(URL, METHOD_NAME);
SoapObject obj, obj1;
ArrayList<HashMap<String,String>> listica=new
ArrayList<HashMap<String,String>>();
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
try
{
//aca me da error y se va
AndroidHttpTransport aht=new AndroidHttpTransport(URL);
aht.call(SOAP_ACTION,envelope);
obj1 = (SoapObject) envelope.bodyIn;
SoapObject obj2 =(SoapObject) obj1.getProperty(0);
obj = (SoapObject) envelope.getResponse();
obj1 = (SoapObject) obj.getProperty("diffgram");
filas = (SoapObject) obj1.getProperty("NewDataSet");
for (int i = 0; i < filas.getPropertyCount(); i++) {
fila = (SoapObject) filas.getProperty(i);
fila.getProperty(0).toString();// value of column 1
fila.getProperty(1).toString();// value of column 2
HashMap<String,String> hashmap=new HashMap<String,
String>();
hashmap.put(FIRST_COLUMN,fila.getProperty(1).toString());;
hashmap.put( SECOND_COLUMN,fila.getProperty(2).toString());;
hashmap.put(THIRD_COLUMN,fila.getProperty(3).toString());;
hashmap.put(FOURTH_COLUMN,fila.getProperty(4).toString());;
listica.add(hashmap);
}
return listica;
}
catch (Exception ex)
{
ex.printStackTrace();
}
return listica ;
}
}
}