Help to deal with sorting / filter ArrayAdapter'a
I have this adapter:
public class DrugAdapter extends ArrayAdapter { Context ctx; LayoutInflater lInflater; ArrayList<InfectionModel> im; public DrugAdapter(Context ctx, ArrayList<InfectionModel> im) { super(ctx, R.layout.drug_list, im); this.ctx = ctx; this.im = im; lInflater = (LayoutInflater) ctx .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return im.size(); } @Override public Object getItem(int position) { return im.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { view = lInflater.inflate(R.layout.drug_list, parent, false); } String title = im.get(position).getTitle(); ImageView img; String liter = im.get(position).getTitle().substring(0, 1); //int color = new RandomColor().getMatColor("500"); TextDrawable drawable = TextDrawable.builder() .beginConfig() .textColor(Color.WHITE) .useFont(Typeface.DEFAULT) .toUpperCase() .endConfig() .buildRound(liter, MaterialColorPalette.getRandomColor("100")); ((TextView) view.findViewById(R.id.txt)).setText(Html.fromHtml(title)); img = (ImageView) view.findViewById(R.id.image_view); img.setImageDrawable(drawable); return view; } Well, the InfectionModel itself:
private String id; private String content; private String title; private String prew; private String date; private String url_img; public InfectionModel() { } public InfectionModel(String id, String content, String title, String prew, String date, String url_img) { this.id = id; this.content = content; this.title = title; this.prew = prew; this.date = date; this.url_img = url_img; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getPrew() { return prew; } public void setPrew(String prew) { this.prew = prew; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getUrl_img() { return url_img; } public void setUrl_img(String url_img) { this.url_img = url_img; } As I understand it, Filter is out of the box for him because when I call
da.getFilter().filter(charSequence.toString().toLowerCase()); Alas, nothing happens, tell me how you can override the getFilter method so that the sorting works correctly? (Sort by field title)