Estimado Rostan mi clase completa es la siguiente
package saga.com.ec.sagamovil.articulos;
import android.content.Context; import android.database.Cursor; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CursorAdapter; import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView;
import java.util.ArrayList; import java.util.List;
import saga.com.ec.sagamovil.R; import saga.com.ec.sagamovil.sqlite.ContratoPedidos;
/**
- Created by fsigu on 23/1/2017. */
public class ArticulosCursorAdapter extends CursorAdapter implements Filterable {
public ArticulosCursorAdapter(Context context, Cursor c) {
super(context, c, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
return inflater.inflate(R.layout.list_item_articulo,parent,false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
//referencias UI
TextView articuloText = (TextView) view.findViewById(R.id.tv_articulo);
TextView cantidadText = (TextView) view.findViewById(R.id.tv_cantidad_articulo);
TextView precioText = (TextView) view.findViewById(R.id.tv_precio_articulo);
//get valores
String codigo=cursor.getString(cursor.getColumnIndex(ContratoPedidos.Productos.CODIGO));
String articulo=cursor.getString(cursor.getColumnIndex(ContratoPedidos.Productos.NOMBRE));
String existencia=cursor.getString(cursor.getColumnIndex(ContratoPedidos.Productos.SALDO));
String precio=cursor.getString(cursor.getColumnIndex(ContratoPedidos.Productos.PRECIO));
//setup
articuloText.setText(articulo);
cantidadText.setText(existencia);
precioText.setText(precio);
}
@Override
public Filter getFilter() {
Filter filter = new Filter() {
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
List<String> arrayListNames = (List<String>) results.values;
notifyDataSetChanged();
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
ArrayList<String> FilteredArrayNames = new ArrayList<String>();
// perform your search here using the searchConstraint String.
constraint = constraint.toString().toLowerCase();
for (int i = 0; i < mDatabaseOfNames.size(); i++){
String dataNames = mDatabaseOfNames.get(i);
if (dataNames.toLowerCase().startsWith(constraint.toString())) {
FilteredArrayNames.add(dataNames);
}
}
results.count = FilteredArrayNames.size();
results.values = FilteredArrayNames;
Log.e("VALUES", results.values.toString());
return results;
}
};
return filter;
}
}