package com.example.user.sortiment; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; import java.util.ArrayList; import java.util.List; import java.util.Objects; /** * Created by user on 11.05.2018 */ public class SortimentAdapter extends BaseAdapter { LayoutInflater mInflator; List<Sortiment> map; List<Sortiment> filterMap; public void performFiltering(CharSequence constraint) { String filterString = constraint.toString().toLowerCase(); if (Objects.equals(filterString, "")) { filterMap = map; notifyDataSetChanged(); return; } int count = map.size(); filterMap = new ArrayList<Sortiment>(count); Sortiment filterableSortiment ; for (int i = 0; i < count; i++) { filterableSortiment = map.get(i); if (filterableSortiment.name.toLowerCase().contains(filterString)) { filterMap.add(filterableSortiment); } } notifyDataSetChanged(); } public SortimentAdapter(Context c, List<Sortiment> inputMap) { mInflator = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); map = inputMap; filterMap = inputMap; } @Override public int getCount() { return filterMap.size(); } @Override public Object getItem(int position) { return filterMap.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = mInflator.inflate(R.layout.item_layout,null); TextView nameTextView = (TextView) v.findViewById(R.id.nameTextView); TextView priceTextView = (TextView) v.findViewById(R.id.priceTextView); Sortiment viewObject = filterMap.get(position); nameTextView.setText(viewObject.name); //priceTextView.setText(String.format("%.0f", prices.get(position))); priceTextView.setText(viewObject.ean.toString()); return v; }
constraint
filterString
count
i
filterMap
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)