Android - Crear columnas de forma dinámica en un tablelayout

 
Vista:
Imágen de perfil de Sandra

Crear columnas de forma dinámica en un tablelayout

Publicado por Sandra (4 intervenciones) el 11/08/2016 22:45:29
Qué tal, tengo una duda, ¿alguien sabe cómo crear columnas de forma dinámica en una tabla hecha en android, sé cómo agregar las filas, pero necesito que en las columnas me aparezcan ciertos datos que obtengo desde una consulta a un servicio web?

Tengo un Asynctask:
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
private class GetDatos extends AsyncTask<String, Void, Void> {
 
    final String SOAP_ACTION = "http://tempuri.org/IServicioTallasAndroid/ListadoTallasA";
    final String METHOD = "ListadoTallasA";
    final String NAMESPACE = "http://tempuri.org/";
    final String ENDPOINTWS = "http://192.1.1.82/SP_Catalogos/ServicioTallasAndroid.svc";
 
 
 
    protected Void doInBackground(String... params) {
        listaTodo.clear();
        SoapObject userRequest = new SoapObject(NAMESPACE, METHOD);
        userRequest.addProperty("estilo", params[0]);
 
        xmodelo = params[0].toString();
 
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(userRequest);
        envelope.dotNet = true;
 
        try{
            HttpTransportSE androidHttpTransport = new HttpTransportSE(ENDPOINTWS);
            androidHttpTransport.debug = true;
            androidHttpTransport.call(SOAP_ACTION, envelope);
 
            SoapObject res= (SoapObject)envelope.bodyIn;
            SoapObject t=(SoapObject)res.getProperty("ListadoTallasAResult");
 
            for(int i=0; i<t.getPropertyCount(); i++){
                SoapObject bank = (SoapObject)t.getProperty(i);
 
 
 
                String estilo = bank.getProperty("Estilo").toString();
                String tienda = bank.getProperty("Tienda").toString().replaceAll(" ", "");
                String tallas = bank.getProperty("Tallas").toString();
                String cantidad = bank.getProperty("Cantidad").toString();
 
                p = new Productos(estilo, tienda, tallas, cantidad);
 
 
 
                listaTodo.add(p);
 
            }
            //respuesta = "Estilo: " + cantidad + "\nTienda: " + costo + "\nTallas: " + descripcion/*envelope.getResponse().toString()*/;
 
        }
        catch (Exception e){
            e.printStackTrace();
 
        }
 
        return null;
    }
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
 
        tl = (TableLayout)findViewById(R.id.miTableLayout);
 
        for (int z = 0; z < listaTodo.size(); z++) {
 
 
            filas = new TableRow(getApplicationContext());
            tvTiendas = new TextView(getApplicationContext());
            tvCantidad = new TextView(getApplicationContext());
            tvTallas = new TextView(getApplicationContext());
 
            filas.setLayoutParams(new TableRow.LayoutParams(
                    TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.MATCH_PARENT));
 
            tvTiendas.setText(listaTodo.get(z).getTienda());
            tvCantidad.setText(listaTodo.get(z).getCantidad());
            tvTallas.setText(listaTodo.get(z).getTallas());
 
            filas.addView(tvTiendas);
            filas.addView(tvCantidad);
 
            filas.addView(tvTallas);
            //tvItemName1.setText(listaTodo.get(z).getEstilo());
            tl.addView(filas, new TableLayout.LayoutParams(
                    TableLayout.LayoutParams.WRAP_CONTENT,
                    TableLayout.LayoutParams.MATCH_PARENT));
 
        }
 
 
    }
}

En el método post es donde hago la tabla, pero necesito poner las tallas como columnas y me salen en fila.

Ejemplo: Introduzco el modelo de un producto y me muestra lo siguiente:



I6f3x

La primera columna muestra las tiendas, la segunda la cantidad de producto en existencia y la tercera las tallas.
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
Imágen de perfil de Sandra

Crear columnas de forma dinámica en un tablelayout

Publicado por Sandra (4 intervenciones) el 12/08/2016 00:04:38
Alguien que me pueda ayudar? por favor, estoy pérdida :(
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar