I have a problem in Android Studio. First I leave the BaseAdapter:
public class AdaptadorGaleriaProductos extends BaseAdapter {
private List<Producto> productosArray = new ArrayList<Producto>();
Context context;
int background;
private AdaptadorBaseDeDatos adapDB;
public AdaptadorGaleriaProductos(Context context, String idCategoria)
{
super();
this.context = context;
//establecemos un marco para las imágenes (estilo por defecto proporcionado)
//por android y definido en /values/attr.xml
TypedArray typedArray = context.obtainStyledAttributes(R.styleable.Gallery1);
background = typedArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
typedArray.recycle();
crearAdaptadorDB();
Cursor productos;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
boolean conCero = sp.getBoolean("productosCero", false);
if (conCero) {
productos = adapDB.obtenerProductosPorCategoriaConCero(idCategoria);
} else {
productos = adapDB.obtenerProductosPorCategoria(idCategoria);
}
while (productos.moveToNext()) {
String id = productos.getString(0);
String nombre = productos.getString(1);
String codigo = productos.getString(2);
int cantidad = productos.getInt(3);
double precioMinorista = productos.getDouble(4);
double precioMayorista = productos.getDouble(5);
String foto = productos.getString(6);
String descripcion = productos.getString(7);
Producto prod = new Producto(id, nombre, codigo, cantidad, precioMinorista, precioMayorista, foto, descripcion);
productosArray.add(prod);
}
}
@Override
public int getCount()
{
return productosArray.size();
}
@Override
public Producto getItem(int position)
{
return productosArray.get(position);
}
@Override
public long getItemId(int position)
{
return getItem(position).getCodigoHash();
}
@Override
public View getView(int position, View view, ViewGroup parent) {
ImageView imagen = new ImageView(context);
final Producto item = getItem(position);
try {
Glide.with(imagen.getContext())
.load(item.getIdImagen())
.into(imagen);
} catch(Exception e) {
}
//se aplica el estilo
imagen.setBackgroundResource(background);
return imagen;
}
And the Activity:
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_galeria_productos);
TypedArray typedArray = this.obtainStyledAttributes(R.styleable.Gallery1);
background = typedArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
typedArray.recycle();
String idCategoria = getIntent().getStringExtra(EXTRA_PARAM_ID);
adapGaleriaProductos = new AdaptadorGaleriaProductos(this, idCategoria);
imagenSeleccionada = (ImageView) findViewById(R.id.seleccionada);
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(adapGaleriaProductos);
}
public void eliminarProducto(final AdaptadorGaleriaProductos adap) {
crearAdaptadorDB();
this.adapDB.eliminarProducto(adap.getItem(this.savePosition).getId());
adap.notifyDataSetChanged();
}
When I delete a product, the activity does not reflect the change instantly. I have to leave and re-enter to see the changes. As you can see, I've tried with notifyDataSetChanged (), but it does not work.
Thank you!