I am carrying out a product project in a local database very similar to the project that Bruno Sosa Fast Tag consulted Android Studio Filter, ListView With Customized adapter and the user David Minaya helped him, I applied the solution that David Minaya applied and I did not filter any data. Only the list is deleted and it does not appear but I do not know what I am doing wrong, if you could help me, I would appreciate it. Thank you.
this is my class list3 that would be the equivalent to the contacts class of the example.
public class Lista3 {
private String Id, Usuario;
private byte[]Imagen;
public Lista3(String id,String usuario, byte[] imagen) {
super();
Id=id;
Usuario = usuario;
Imagen = imagen;
}
public String getId() {
return Id;
}
public void setId(String id) {
Usuario = id;
}
public String getUsuario() {
return Usuario;
}
public void setUsuario(String usuario) {
Usuario = usuario;
}
public byte[] getImagen() {
return Imagen;
}
public void setImagen(byte[] imagen) {
Imagen = imagen;
}
}
This is my adapter class.
public class AdaptadorLista3 extends BaseAdapter {
private Context context;
private ArrayList<Lista3> list;
ArrayList<Lista3> copylist=new ArrayList<>();
public AdaptadorLista3(Context context,ArrayList<Lista3> list) {
this.context = context;
this.list = list;
this.copylist.addAll(list);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Lista3 item=(Lista3)getItem(position);
convertView= LayoutInflater.from(context).inflate(R.layout.item_lista_usuarios,null);
ImageView imgfoto= (ImageView) convertView.findViewById(R.id.imvicono);
TextView Usuario= (TextView) convertView.findViewById(R.id.lblUsuario);
TextView Id= (TextView) convertView.findViewById(R.id.lblIdUsuario);
byte[] icono=item.getImagen();
Bitmap bitmap= BitmapFactory.decodeByteArray(icono, 0, icono.length);
imgfoto.setImageBitmap(bitmap);
Usuario.setText(item.getUsuario());
Id.setText(item.getId());
return convertView;
}
/* Filtra los datos del adaptador */
public void filtrar(String texto) {
// Elimina todos los datos del ArrayList que se cargan en los
// elementos del adaptador
list.clear();
// Si no hay texto: agrega de nuevo los datos del ArrayList copiado
// al ArrayList que se carga en los elementos del adaptador
if (texto.length() == 0) {
list.addAll(copylist);
} else {
// Recorre todos los elementos que contiene el ArrayList copiado
// y dependiendo de si estos contienen el texto ingresado por el
// usuario los agrega de nuevo al ArrayList que se carga en los
// elementos del adaptador.
for (Lista3 lista3 : copylist) {
if (lista3.getUsuario().contains(texto)) {
list.add(lista3);
}
}
}
// Actualiza el adaptador para aplicar los cambios
notifyDataSetChanged();
}
}
and I execute it in this way.
public void onTextChanged(CharSequence s, int start, int before, int count) {
adaptadorLista3.filtrar(Buscar.getText().toString());
}
I do not know what I would be wrong, the data I'm filling from sqlite request your help please.