My problem is editing on click see
But I need that on click "EDITAR" it does
I have a Button
that set my DELETE button visible for each element of the ListView
.
But it only sets visible the last element. How can I set all the elements visible ?
MyButton is Ocult in my custom adapter and when I call the method that set my buttons visible ... This button Works Fine.
//button "EDITAR"
btnBoton2 = (Button)findViewById(R.id.eliminar_primero);
btnBoton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0)
{
personaAdapter.setVisibility();
}
});
My adapter :
public class PersonaCustomAdapter extends ArrayAdapter<Persona> {
Context context;
int layoutResourceId;
ArrayList<Persona> data = new ArrayList<Persona>();
private PersonaDAO personaDao;
UserHolder holder;
int posicion;
public PersonaCustomAdapter(Context context, int layoutResourceId,ArrayList<Persona> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
holder = null;
posicion = position;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.textName = (TextView) row.findViewById(R.id.textView1);
holder.btnEdit = (Button) row.findViewById(R.id.boton_eliminame);
holder.btnEdit.setVisibility(View.INVISIBLE);
row.setTag(holder);
} else {
holder = (UserHolder) row.getTag();
}
personaDao = new PersonaDAO(context);
personaDao.open();
holder.textName.setText(persona.getNombre_persona());
holder.btnEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (persona.getId_persona() > 0) {
MyActivity hola = new MyActivity();
if ( personaDao.eliminarPersona(persona)){
data.remove(position);
notifyDataSetChanged();
} else {
System.out.println("No se logro eliminar");
}
}
}
});
return row;
}
public void setVisibility()
{
// Here is where i getVisibility of my elementos.. is INVISIBLE by Default but
//only setVisible The lastElement
if(holder.btnEdit.getVisibility() == View.INVISIBLE){
holder.btnEdit.setVisibility(View.VISIBLE);
} else if(holder.btnEdit.getVisibility() == View.VISIBLE){
holder.btnEdit.setVisibility(View.INVISIBLE);
}
notifyDataSetChanged();
}
public int getCount() {
return data.size();
}