problem generate dynamic table android studio

0

I have a problem with Android Studio, since I repeat the tables twice in some devices and in others, the code generates 3 tables with different information, but in certain devices the same ones are repeated, leaving 6 as a result, if someone could guide me, I would appreciate it, I attach the code. As you can see, there are two more classes, one to create a pdf of what you see on screen and another to send it as an attachment by mail, but those work well.

public class principal1 extends Activity {

//Directorios y rutas
String carpeta = "/pdf";
File sdCard, directory = null;
String archivo;
String pdf;

//var de envio
Boolean error=false;
//variables datepicker
private static final String CERO = "0";
private static final String BARRA = "-";

//Calendario para obtener fecha & hora
public final Calendar c = Calendar.getInstance();

//variables fecha
final int mes = c.get(Calendar.MONTH);
final int dia = c.get(Calendar.DAY_OF_MONTH);
final int anio = c.get(Calendar.YEAR);

ButtonRectangle btn_mail;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal1);
    btn_mail = (ButtonRectangle) findViewById(R.id.btn_mail);
    obtenerFecha();

    btn_mail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            btn_mail.setVisibility(View.GONE);

            try {
                tomafoto();
                manipulatePdf();
                sendMail();
            } catch (DocumentException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}

public void obtenerFecha() {
    DatePickerDialog recogerFecha = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            final int mesActual = month + 1;
            String diaFormateado = (dayOfMonth < 10) ? CERO + String.valueOf(dayOfMonth) : String.valueOf(dayOfMonth);
            String mesFormateado = (mesActual < 10) ? CERO + String.valueOf(mesActual) : String.valueOf(mesActual);
            String etFecha = year + BARRA + mesFormateado + BARRA + diaFormateado;
            SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(principal1.this);
            SharedPreferences.Editor editor = setting.edit();
            editor.putString("etFecha", etFecha);
            editor.commit();
            procesafecha();
        }
    }, anio, mes, dia);
    recogerFecha.show();
}
public void procesafecha() {
    Tabla tabla = new Tabla(this, (TableLayout) findViewById(R.id.tabla));
    tabla.agregarCabecera(R.array.cabecera_tabla);
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(principal1.this);
    String fecha_resumen = setting.getString("etFecha", "");
    String DateFormat = "";
    SQLiteHelper MDB = new SQLiteHelper(principal1.this);
    try {
        Tabla tabla2 = new Tabla(this, (TableLayout) findViewById(R.id.tabla2));
        tabla2.agregarCabecera(R.array.cabecera_2);
        ArrayList elementos2 = new ArrayList();
        elementos2.add(MDB.report(fecha_resumen).getEquipo());
        elementos2.add(MDB.report(fecha_resumen).getTipo_faena());
        elementos2.add(MDB.report(fecha_resumen).getLugar_faena());
        elementos2.add(MDB.report(fecha_resumen).getOperador());
        tabla2.agregarFilaTabla(elementos2);

    } catch (Exception e) {
        e.getCause();
        Tabla tabla2 = new Tabla(this, (TableLayout) findViewById(R.id.tabla2));
        ArrayList elementos2 = new ArrayList();
        elementos2.add("Sin información");
        elementos2.add("Sin información");
        elementos2.add("Sin información");
        elementos2.add("Sin información");
        tabla2.agregarFilaTabla(elementos2);
    }

    try {
        long vi = MDB.r_valores_min(fecha_resumen).getTiempo_inicio();
        if (vi==0){
            Tabla tabla3 = new Tabla(this, (TableLayout) findViewById(R.id.tabla3));
            tabla3.agregarCabecera(R.array.cabecera_3);
            ArrayList elementos3 = new ArrayList();
            elementos3.add("Sin información");
            elementos3.add("Sin información");
            elementos3.add("Sin información");
            elementos3.add("Sin información");
            elementos3.add("Sin información");
            tabla3.agregarFilaTabla(elementos3);
            btn_mail.setVisibility(View.GONE);
        } else {
            SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");
            String DateFormat2 = formatter2.format(vi);
            String vci = MDB.r_valores_min(fecha_resumen).getTipo_control();
            String ci = MDB.r_valores_min(fecha_resumen).getValor_tipo_control();
            long vf = MDB.r_valores_max(fecha_resumen).getTiempo_termino();
            SimpleDateFormat formatter3 = new SimpleDateFormat("HH:mm:ss");
            String DateFormat3 = formatter3.format(vf);
            String vcf = MDB.r_valores_max(fecha_resumen).getTipo_control();
            String cf = MDB.r_valores_max(fecha_resumen).getValor_tipo_control();
            long sv= vf-vi;
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
            int millisec = 0, sec = 0, min = 0, hour = 0;
            long millislong = 0;
            millislong = sv;
            if (millislong > 1000) {
                sec = (int) (millislong / 1000);
                millisec = (int) millislong % 1000;
                if (sec >= 60) {
                    min = sec / 60;
                    sec = sec % 60;
                }
                if (min >= 60) {
                    hour = min / 60;
                    min = min % 60;
                }
                cal.clear();
                cal.set(Calendar.HOUR_OF_DAY, hour);
                cal.set(Calendar.MINUTE, min);
                cal.set(Calendar.SECOND, sec);
                cal.set(Calendar.MILLISECOND, millisec);
                DateFormat = formatter.format(cal.getTime());
            }
            SimpleDateFormat formatter4 = new SimpleDateFormat("HH:mm:ss");
            String DateFormat4 = formatter3.format(sv);
            Tabla tabla3 = new Tabla(this, (TableLayout) findViewById(R.id.tabla3));
            tabla3.agregarCabecera(R.array.cabecera_3);
            ArrayList elementos3 = new ArrayList();
            elementos3.add(DateFormat2);
            elementos3.add(DateFormat3);
            elementos3.add(DateFormat);
            elementos3.add(vci + ": " + ci);
            elementos3.add(vcf + ": " + cf);
            tabla3.agregarFilaTabla(elementos3);
        }
    } catch (Exception e) {
        e.getCause();
    }
    try {
        Integer cuenta_reg = MDB.getAllValuesRegistroProeq(1).size();
        ArrayList<String> elementos = new ArrayList();
        String actividad = "";
        String cuenta = "";
        for (int i = 0; i <= cuenta_reg; i++) {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
            int millisec = 0, sec = 0, min = 0, hour = 0;
            long millislong = 0;
            millislong = MDB.Operacion(fecha_resumen).get(i).getSuma_tiempo();
            SharedPreferences.Editor editor = setting.edit();
            editor.putLong("mi_ope", MDB.Operacion(fecha_resumen).get(i).getSuma_tiempo());
            editor.commit();
            if (millislong > 1000) {
                sec = (int) (millislong / 1000);
                millisec = (int) millislong % 1000;
                if (sec >= 60) {
                    min = sec / 60;
                    sec = sec % 60;
                }
                if (min >= 60) {
                    hour = min / 60;
                    min = min % 60;
                }
                cal.clear();
                cal.set(Calendar.HOUR_OF_DAY, hour);
                cal.set(Calendar.MINUTE, min);
                cal.set(Calendar.SECOND, sec);
                cal.set(Calendar.MILLISECOND, millisec);
                DateFormat = formatter.format(cal.getTime());
                actividad = MDB.Operacion(fecha_resumen).get(i).getActividad();
                cuenta = MDB.Operacion(fecha_resumen).get(i).getCuenta_nombre().toString();
                elementos.add(fecha_resumen);
                elementos.add(actividad);
                elementos.add(cuenta);
                elementos.add(DateFormat);
                tabla.agregarFilaTabla(elementos);
            } else {
                elementos.add(fecha_resumen);
                elementos.add("Operación");
                elementos.add("0");
                elementos.add("00:00:00");
                tabla.agregarFilaTabla(elementos);
            }
        }

    } catch (Exception e) {
        e.getCause();
    }
    try {
        setting = PreferenceManager.getDefaultSharedPreferences(principal1.this);
        long ope = setting.getLong("mi_ope", 0);
        long millislong = ope;
        ArrayList<String> elementos = new ArrayList();
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        int millisec = 0, sec = 0, min = 0, hour = 0;
        if (millislong > 1000) {
            sec = (int) (millislong / 1000);
            millisec = (int) millislong % 1000;
            if (sec >= 60) {
                min = sec / 60;
                sec = sec % 60;
            }
            if (min >= 60) {
                hour = min / 60;
                min = min % 60;
            }
            cal.clear();
            cal.set(Calendar.HOUR_OF_DAY, hour);
            cal.set(Calendar.MINUTE, min);
            cal.set(Calendar.SECOND, sec);
            cal.set(Calendar.MILLISECOND, millisec);
            DateFormat = formatter.format(cal.getTime());
            elementos.add(fecha_resumen);
            elementos.add("Todas");
            elementos.add("Total Jornada");
            elementos.add(DateFormat);
            tabla.agregarFilaTabla(elementos);
        } else {
            elementos.add(fecha_resumen);
            elementos.add("Todas");
            elementos.add("Total Jornada");
            elementos.add("Sin Información");
            tabla.agregarFilaTabla(elementos);
        }

    } catch (Exception e) {

    }
}
    
asked by Jose Pacheco Ch. 10.04.2018 в 03:29
source

1 answer

0

The error was in the way the function was called, inside the onCreate it is replaced by the following lines and the problem is solved

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal4);
    btn_mail = (ButtonRectangle) findViewById(R.id.btn_mail);
    btn_report = (ButtonRectangle) findViewById(R.id.btn_report);
    obtenerFecha();
    btn_mail.setVisibility(View.GONE);

    btn_report.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            btn_report.setVisibility(View.GONE);
            btn_mail.setVisibility(View.VISIBLE);
            procesafecha();

        }
    });

    btn_mail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_mail.setVisibility(View.GONE);
            btn_report.setVisibility(View.GONE);

            try {
                tomafoto();
                manipulatePdf();
                sendMail();
            } catch (DocumentException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
    
answered by 24.05.2018 в 09:00