Buenas tardes, soy nuevo en el foro así que me disculpan si realizo mal la pregunta o es una pregunta muy tonta.
Resulta que estoy haciendo una aplicación y tengo un recyclerview
donde este posee un edittext
el cual lleva la cantidad de productos que voy a solicitar, hasta ahí todo bien, solo que cuando edito la cantidad, no la almacena de una vez en el adapter
sino que me queda en la vista hasta que agregue un nuevo elemento que se recorre el adapter y o almacena, en este es mi CustomAdapter
public class AdaptadorPedido extends
RecyclerView.Adapter<AdaptadorPedido.MyHolder> {
Context context;
List<DataAdapter> datos;
String[] etValArr;
String[] Fin;
public AdaptadorPedido(Context context, List<DataAdapter> datos) {
this.context = context;
this.datos = datos;
etValArr = new String[datos.size()];
Fin = new String[datos.size()];
}
@Override
//public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.row_view, parent, false);
MyHolder mh = new MyHolder(view, new CustomEtListener());
return mh;
//return new MyHolder(view);
}
@Override
public void onBindViewHolder(final MyHolder holder, final int position) {
holder.Nproducto.setText(datos.get(position).getNombre());
holder.Lab.setText(datos.get(position).getLabo());
holder.Lista.setText(datos.get(position).getList());
holder.precio.setText(datos.get(position).getPre());
holder.Cantidad.setText(datos.get(position).getCant());
holder.myCustomEtListener.updatePosition(position);
holder.Cantidad.setText(etValArr[position]);
holder.Nproducto.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder adb = new AlertDialog.Builder(v.getContext());
adb.setTitle("Eliminar?");
adb.setMessage("¿Seguro que desea sacar este producto de la OP ?");
adb.setNegativeButton("No",null);
adb.setPositiveButton("Si",new AlertDialog.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
datos.remove(position);
notifyDataSetChanged();
}
});
adb.show();
return false;
}
});
holder.Lab.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder adb = new AlertDialog.Builder(v.getContext());
adb.setTitle("Eliminar?");
adb.setMessage("¿Seguro que desea sacar este producto de la OP ?");
final int positionToRemove = position;
adb.setNegativeButton("No",null);
adb.setPositiveButton("Si",new AlertDialog.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
datos.remove(position);
notifyDataSetChanged();
}
});
adb.show();
return false;
}
});
}
@Override
public int getItemCount() {
return datos.size();
}
public class MyHolder extends RecyclerView.ViewHolder{
TextView Nproducto, Lab, Lista, precio;
EditText Cantidad;
public CustomEtListener myCustomEtListener;
//public MyHolder(View itemView) {
public MyHolder(View itemView, CustomEtListener myList) {
super(itemView);
Nproducto = (TextView)itemView.findViewById(R.id.tv_Producto);
Lab = (TextView)itemView.findViewById(R.id.tv_Lab);
Lista = (TextView)itemView.findViewById(R.id.tv_Lista);
precio = (TextView)itemView.findViewById(R.id.tv_Precio);
Cantidad = (EditText)itemView.findViewById(R.id.et_cant);
myCustomEtListener = myList;
Cantidad.addTextChangedListener(myCustomEtListener);
}
}
public static class DataAdapter{
String Nombre,Labo, List, Pre, Cant;
public DataAdapter(String Nombre,String Labo,String List,String Pre,String Cant){
this.Nombre = Nombre;
this.Labo = Labo;
this.List = List;
this.Pre = Pre;
this.Cant = Cant;
}
public String getNombre() {
return Nombre;
}
public void setNombre(String nombre) {
Nombre = nombre;
}
public String getLabo() {
return Labo;
}
public void setLabo(String labo) {
Labo = labo;
}
public String getList() {
return List;
}
public void setList(String list) {
List = list;
}
public String getPre() {
return Pre;
}
public void setPre(String pre) {
Pre = pre;
}
public String getCant() {
return Cant;
}
public void setCant(String cant) {
Cant = cant;
}
}
private class CustomEtListener implements TextWatcher{
private int position;
public void updatePosition(int position){
this.position = position;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
etValArr[position] = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
}
}
Agradezco su ayuda.