Good I am trying to do something that probably is of the most complex things that I carry out in android.
Let's see, I put you in a situation, I have a list of currencies in which when clicking another list is activated right on your right. This second list should show the years since you took the currency in the indicated country (this part of choosing a country will not come out, we will assume it is Germany always) going through the database and loading only the years, which will be green if we have it or in red if we do not have it, with the possibility of clicking on an item in the list (which contains all the years that the currency has in the country selected: this case in Germany) if we click on an item in green (we have the currency of that year) will become red and vice versa, the problem is that when I put one that was green to red by clicking on it, that is, removing one year of that year from my collection is removed without problems (until here) but as soon as I move the scroll of the list and make disappear the item that changes (with disappearing I mean scroll so much that it happens outside the screen) and I fly to scroll to see that date that I have changed, when removing it and put it back in the vision of the panta I came out again as I was, that is, green, so when I make a modification and I scroll I lose it.
I know that there is an asyntaskloader that is the one that I am trying to do so that I can keep the red and green ones still scrolling but of course it is very complex for me. I will show the screen of the list of currencies and dates below.
You can see how I put the dates in red that I do not have without problems when clicking, but when you move the scroll of the list they are reset to how they were.
I am trying to mount a Loader as follows
public class lista_monedas_comprobacion_loader extends AsyncTaskLoader<List<Moneda>> {
private static final String LOG_TAG = lista_monedas_comprobacion_loader.class.getName();
//Query URL
private String query;
//datos que necesito para crear la consulta ( qquery)
private String nombrePais;
private String tipoMoneda;
public lista_monedas_comprobacion_loader(@NonNull Context context,String nombrePais,String tipoMoneda) {
super(context);
this.nombrePais = nombrePais;
this.tipoMoneda = tipoMoneda;
}
@Override
protected void onStartLoading() {
forceLoad();
}
@Nullable
@Override
public List<Moneda> loadInBackground() {
sqlite sqlite = new sqlite(getContext());
SQLiteDatabase db = sqlite.getReadableDatabase();
//Si hemos abierto correctamente la base de datos
List<Moneda> monedas = new ArrayList<>();
query = "SELECT * \n" +
"FROM colecciones\n" +
"WHERE coleccion_pais_nombre = '" + nombrePais + "'\n AND \n" +
"coleccion_moneda_tipo = '" + tipoMoneda + "'";
if (query == null){
return null;
}
else{
// si no es null
Cursor c = db.rawQuery(query, null);
//listaMonedas.clear();
if (c != null) {
if (c.moveToFirst()) {
do {
int id = c.getInt(0);
String tipo = c.getString(1);
String pais = c.getString(2);
String año = c.getString(3);
int tenencia = c.getInt(4);
Moneda moneda;
moneda = new Moneda(id, tipo, pais, año, 1);
moneda.print();
System.out.println("=================================");
monedas.add(moneda);
} while (c.moveToNext());
}
}
//Cerramos la base de datos
db.close();
sqlite.close();
}
return monedas;
}
}
In the event that it works, I do not think, I do not know how to execute it in the class, I do not even know if I'm close to achieving it.
Beforehand, say thank you very much, any additional information you need to contribute, let me know.