I have a custom ListView and a button that when I press it saves a data, in this button I use "SharedPreferences" the shared preferences, the problem is that the adapter (Java Code) is like this:
public class Adaptador extends BaseAdapter{
Then I can not call the SharedPreferences method to save the data so what I did create a Java file called 'datos.java' and create the function 'SaveData' to save the data that would be like this:
public void GuardarDatos(String posicion, boolean valor)
{
SharedPreferences prefs = getSharedPreferences("settingAlarmas", this.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(posicion, valor); //ID - ESTADO
editor.apply();
}
The function 'SaveData' is being called from the adapter in this way:
Datos d = new Datos();
d.GuardarDatos("valor",true); //ID- Y Valor
The problem is because of the context in which it is called by the this
in which this only serves for the current activity but I do not know what context to use to make the application because other methods of other classes are being called to operate the custom adapter