Android - Problemas al llenar Spinner Android Studio

 
Vista:
sin imagen de perfil

Problemas al llenar Spinner Android Studio

Publicado por Angel Grullon (1 intervención) el 21/10/2016 16:21:01
Buen dia!

Mi problema es que quiero llenar un Spinner con datos de una base de datos MySql, los archivos php estan bien porque ya los he probado, el Spinner solo me muestra el primer registro de la tabla.

El codigo que tengo es el siguiente:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// METODO PARA CONSULTAR LOS DATOS
 
private class ConsultarDatos extends AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... urls) {
 
        // params comes from the execute() call: params[0] is the url.
        try {
            return downloadUrl(urls[0]);
        } catch (IOException e) {
            return "Unable to retrieve web page. URL may be invalid.";
 
        }
    }
 
    // onPostExecute displays the results of the AsyncTask.
    @Override
    protected void onPostExecute(String result) {
 
        ArrayList<String> lista = new ArrayList<String>();
 
        JSONArray array = null;
        try {
            array = new JSONArray(result);
            for(int i = 0; i < array.length(); i++){
                lista.add(array.get(i).toString());
            }
 
 
            ArrayAdapter arrayAdapter = new ArrayAdapter(Principal.this, android.R.layout.simple_dropdown_item_1line,lista);
            arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnerProvincias.setAdapter(arrayAdapter);
 
        } catch (JSONException e){
            e.printStackTrace();
        }
    }
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder