listview, do not show items if you do not have data

0

I'm doing a program on a database of series, I have a base which saves me a series of Edittext, like the name of the series, chapters, seasons, etc, what I want to show in a listview is the Name of the series, the season I'm going through and the chapter I'm going through, the problem is that when I load the data in the listview, I also see blank data, that is, if I add the name of the series to the base "pepe" (primary key in the base), season "1" and chapter "2", in the listview I think pepe TEMP 1 CAP 2, but if I keep only the name of the series and do not put anything in season and chapter, in the listview I get pepe TEMP CAP, is there any way that it does not show the name of the series in listview if I only keep the name of the series and do not put anything in season and chapter?

here is the code I use to extract the data from the base and show them in listview, the base contains some fields (edittext) more, but I just want to show the ones I mentioned, that's why the name of the series is the row 0, season is row 6 and chapter 7, can you help me ?, thanks.

public void cargarvistos() {
    AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "series.db", null, 1);
    SQLiteDatabase bd = admin.getReadableDatabase();
    Cursor fila = bd.rawQuery("select * from datos order by nombre asc", null);// muestra registros por numero ascendente
    int cantidad = fila.getCount();
    int i = 0;
    String[] listado = new String[cantidad];
    if (fila.moveToFirst()) {
        do {
            String linea = fila.getString(0)+"\n TEMP.  " + fila.getString(6)+ "  CAP.  " + fila.getString(7);
            listado[i] = linea;
            i++;
        } while (fila.moveToNext());
        bd.close();
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.color_blanco_listview1, listado);
    ListView lista = (ListView) findViewById(R.id.listavistos);
    lista.setAdapter(adapter);
}
    
asked by Jose Joaquin 26.02.2018 в 11:59
source

1 answer

0

You can opt for an if inside the do-while, checking if the variable TEMP and CAP are null or not. I propose something like this:

do {
            String linea = fila.getString(0)+"\n";
            if (!fila.getString(6).equals("")) linea += "TEMP.  " + fila.getString(6);
            if (!fila.getString(7).equals("")) linea += "CAP.  " + fila.getString(7);
            listado[i] = linea;
            i++;
        } while (fila.moveToNext());
    
answered by 26.02.2018 / 12:10
source