Friends your help please!
I need to make a crud that shows me information about a web service that is already published in:
The problem I have is that it does not show me the list of products.
package ec.edu.uisrael.ejemplws;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import java.util.ArrayList;
import java.util.List;
public class cargarProducto extends AppCompatActivity {
/*private static String NAMESPACE="/";*/
/*private static String URL="*//PedidosService?wsdl";
private String resultado;
private Button nuevoProd;
//private GridView actualGrid;
private ArrayList<Object> listaProductos;
private ArrayAdapter<Object> adaptador1;
private android.widget.GridView lista;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listar_producto);
//actualGrid = (GridView)findViewById(R.id.productos);
nuevoProd=(Button)findViewById(R.id.btnNuevoPro);
nuevoProd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(cargarProducto.this, nuevoProducto.class);
startActivity(intent);
}
});
listaProductos=new ArrayList<Object>();
//agrego los productos a la lista
cargarProducto.listarProducto task= new listarProducto();
task.execute();
adaptador1=new ArrayAdapter<Object>(this,android.R.layout.simple_dropdown_item_1line,listaProductos);
lista=(GridView) findViewById(R.id.productos);
lista.setAdapter(adaptador1);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AlertDialog.Builder dialogo1 = new AlertDialog.Builder(cargarProducto.this);
dialogo1.setTitle("Notificación");
dialogo1.setMessage("¿Que desea hacer?");
dialogo1.setCancelable(false);
dialogo1.setPositiveButton("Editar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog1, int which) {
Intent intent = new Intent(cargarProducto.this, editarProducto.class);
startActivity(intent);
}
});
dialogo1.setNegativeButton("Eliminar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogo1, int id) {
Intent intent = new Intent(cargarProducto.this, DeleteProducto.class);
startActivity(intent);
}
});
dialogo1.show();
}
});
//productos.InvalidateViews();
}
/*public void retornarOnClick(View view){
Intent intent = new Intent(this,nuevoProducto.class);
startActivity(intent);
}*/
private class listarProducto extends AsyncTask<Void,Void,Void> {
@Override
protected Void doInBackground(Void... params){
listarProductoWs();
return null;
}
protected void onPostExecute(Void result){
AlertDialog.Builder dialogo= new AlertDialog.Builder(cargarProducto.this);
dialogo.setTitle("Resultado");
dialogo.setMessage(resultado);
dialogo.setNeutralButton("OK",null);
dialogo.show();
}
}
private void listarProductoWs(){
//se ingresa el nombre del metodo del soap
String METHOD_NAME= "listarProductos";
String SOAP_ACTION="listarProductosAction";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//agrego los parametros al servicio, el name es el que sale en el soap
List<String> resultData = new ArrayList<String>();
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(request);
SoapObject response = new SoapObject();
try {
HttpTransportSE transporte= new HttpTransportSE(URL);
transporte.call(SOAP_ACTION,soapEnvelope);
//se procesa el resultado devuelto
response = (SoapObject) soapEnvelope.bodyIn;
//agrega productos a la lista
if (response.getPropertyCount() > 0) {
SoapObject data = null;
try {
data = (SoapObject) response.getProperty(0);
if (data == null) {
listaProductos.add(response.getPropertyAsString(0));
} else {
for (int k = 0; k < 100; k++){
data = (SoapObject) response.getProperty(k);
String aux="";
for (int i = 0; i < data.getPropertyCount(); i++) {
if (i==0){
aux=data.getPropertyAsString(0);
}else{
aux=aux+" , "+data.getPropertyAsString(i);
}
}
listaProductos.add(aux);
}
}
} catch (Exception e) {
}
}
}catch (Exception e){
}
}
public void actulizaGrid_OnClick(View view) {
//producto.setAdapter(adapter);
// actualGrid.refreshDrawableState();
Intent intent = new Intent(cargarProducto.this, cargarProducto.class);
startActivity(intent);
}
}