77import android .widget .ArrayAdapter ;
88import android .widget .Filter ;
99import android .widget .Filterable ;
10- import android .widget .TextView ;
1110
12- import com .blogspot .e_kanivets .moneytracker .R ;
11+ import com .blogspot .e_kanivets .moneytracker .databinding . ViewCategoryItemBinding ;
1312import com .blogspot .e_kanivets .moneytracker .util .CategoryAutoCompleter ;
1413
1514import org .jetbrains .annotations .NotNull ;
1615
1716import java .util .ArrayList ;
1817import java .util .List ;
1918
20- import butterknife .BindView ;
21- import butterknife .ButterKnife ;
22-
23- /**
24- * Custom adapter to autocomplete categories.
25- * Created on 3/18/16.
26- *
27- * @author Evgenii Kanivets
28- */
2919public class CategoryAutoCompleteAdapter extends ArrayAdapter <String > implements Filterable {
20+
3021 private final CategoryAutoCompleter autoCompleter ;
3122
3223 public CategoryAutoCompleteAdapter (Context context , int resource , CategoryAutoCompleter autoCompleter ) {
@@ -36,24 +27,23 @@ public CategoryAutoCompleteAdapter(Context context, int resource, CategoryAutoCo
3627
3728 @ Override
3829 public View getView (int position , View convertView , @ NotNull ViewGroup parent ) {
39- ViewHolder viewHolder ;
30+ ViewCategoryItemBinding binding ;
4031
4132 if (convertView == null ) {
42- convertView = LayoutInflater .from (getContext ()).inflate (R .layout .view_category_item , parent , false );
43- viewHolder = new ViewHolder (convertView );
44- convertView .setTag (viewHolder );
45- } else viewHolder = (ViewHolder ) convertView .getTag ();
33+ binding = ViewCategoryItemBinding .inflate (LayoutInflater .from (getContext ()), parent , false );
34+ convertView = binding .getRoot ();
35+ convertView .setTag (binding );
36+ } else {
37+ binding = (ViewCategoryItemBinding ) convertView .getTag ();
38+ }
4639
4740 final String category = getItem (position );
4841
49- viewHolder .tvCategory .setText (category );
50- viewHolder .ivCancel .setOnClickListener (new View .OnClickListener () {
51- @ Override
52- public void onClick (View v ) {
53- autoCompleter .removeFromAutoComplete (category );
54- remove (category );
55- notifyDataSetChanged ();
56- }
42+ binding .tvCategory .setText (category );
43+ binding .ivCancel .setOnClickListener (v -> {
44+ autoCompleter .removeFromAutoComplete (category );
45+ remove (category );
46+ notifyDataSetChanged ();
5747 });
5848
5949 return convertView ;
@@ -92,15 +82,4 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
9282 }
9383 };
9484 }
95-
96- public static class ViewHolder {
97- @ BindView (R .id .tvCategory )
98- TextView tvCategory ;
99- @ BindView (R .id .iv_cancel )
100- View ivCancel ;
101-
102- public ViewHolder (View view ) {
103- ButterKnife .bind (this , view );
104- }
105- }
10685}
0 commit comments