Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > JAVA
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 02-10-2015
Jose Roman Jose Roman is offline
Miembro
 
Registrado: jul 2006
Ubicación: Colombia
Posts: 361
Poder: 18
Jose Roman Va por buen camino
Retornar multiples valores de un metodo

Cordail saludo desde Colombia,

Antes que todo solo llevo solo 20 dias aprendiendo Java y tratando de incursionar con Android, para ello utilizo Android Studio.

tengo una consulta PHP que me arroja estos Arrays:
Código PHP:
{"alumno":[{"NOMBRE":"SILVA TORRES ELIANA","IDENTI":"1151951743"}]}{"produccion":[{"ID_PRO":"9143"},{"ID_PRO":"9142"},{"ID_PRO":"9141"},{"ID_PRO":"8808"},{"ID_PRO":"8761"},{"ID_PRO":"8613"}]} 
Para conexion y busqueda de los datos realice esto:

Código:
public class Main extends AppCompatActivity {

    private TextView miAlumno;
    private Typeface miFont;
    private Spinner miFactu;
    private String miDato;
    private String miFact;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btAlumno = (Button)findViewById(R.id.btFind);
        miAlumno = (TextView)findViewById(R.id.miTexto);
        miFont = Typeface.createFromAsset(getAssets(),"fonts/courbd.ttf");
        miAlumno.setTypeface(miFont);
        miFactu = (Spinner)findViewById(R.id.cbFact);

        final EditText miCodigo = (EditText)findViewById(R.id.edCod);

        btAlumno.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (miCodigo.getText().toString().length() < 6) {
                    Context context = getApplicationContext();
                    CharSequence text = "EL CODIGO DEBE DE SER DE SEIS DIGITOS";
                    int duration = Toast.LENGTH_SHORT;
                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                } else {
                    new JSONTask().execute("http://192.168.1.37/lfp/produc.php?ID=" + miCodigo.getText());
                }
            }
        });
    }

public class JSONTask extends AsyncTask<String, String, String>{

        @Override
        protected String doInBackground(String... params) {
            HttpURLConnection connection = null;
            BufferedReader reader = null;

            try{
                URL url = new URL(params[0]);
                connection = (HttpURLConnection) url.openConnection();
                connection.connect();

                InputStream stream = connection.getInputStream();

                reader = new BufferedReader(new InputStreamReader(stream));

                StringBuffer buffer = new StringBuffer();

                String line = "";

                while ((line = reader.readLine()) != null){
                    buffer.append(line);
                }

                String finalJson = buffer.toString();
                JSONObject parentObject = new JSONObject(finalJson);
                JSONArray parentArray = parentObject.getJSONArray("alumno");
                JSONObject finalObject;
                StringBuffer finalBufferData = new StringBuffer();


                for (int i = 0; i < parentArray.length(); i++){
                  finalObject = parentArray.getJSONObject(i);
                  String estNombre = finalObject.getString("NOMBRE");
                  if (estNombre == null) {
                      miDato = "ALUMNO NO REGISTRADO";
                  } else {
                      NumberFormat numberfortmat = new DecimalFormat("#,###");
                      String estIdenti = finalObject.getString("IDENTI");
                      estIdenti = numberfortmat.format(Long.valueOf(estIdenti));
                      miDato = "ALUMNO:\n" + "  " + estNombre + "\n  " + estIdenti;
                  }
                }
                return miDato;

            } catch (MalformedURLException e){
                e.printStackTrace();
            } catch (IOException e){
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                if(connection != null){
                    connection.disconnect();
                }
                try {
                    if (reader != null){
                        reader.close();
                    }
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result){
            super.onPostExecute(result);
            miAlumno.setText(result);
        }


    }
La clase JSONTask me ubica bien lo correspondiente a "alumno" , pero no se como hacer para que me arroje los valores correspondientes a "produccion", sin tener que llamar de nuevo a la clase.

Aqui logre ubicar algo pero no se implementarlo bien.

Gracias de antemano.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Retornar valores al programa inicial verde_esmeralda C++ Builder 5 28-08-2014 22:14:55
¿Como retornar varios valores en un Servicio Web? jscubillos5 Delphi para la web 2 10-03-2014 10:40:58
Retornar valores de sp en Firebird hacia Php subzero PHP 1 11-05-2011 03:56:30
Cómo hacer para retornar valores de una Unit a otra karo Varios 6 14-03-2009 21:57:28
Retornar o no retornar desde un script principal dec PHP 6 25-03-2008 00:41:12


La franja horaria es GMT +2. Ahora son las 20:57:55.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi