use of carbon.widget.ListSearchAdapter in project Carbon by ZieIony.
the class SearchToolbarActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<DefaultAvatarTextItem> items = generateItems();
RowListAdapter<DefaultAvatarTextItem> adapter = new RowListAdapter<>(items, AvatarTextRow::new);
RecyclerView recyclerView = findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
searchEditText = findViewById(R.id.searchEditText);
searchEditText.setDataProvider(new ListSearchAdapter<DefaultAvatarTextItem>(items) {
@NotNull
@Override
public String[] getItemWords(DefaultAvatarTextItem item) {
return new String[] { item.getText() };
}
});
searchEditText.setOnFilterListener((SearchEditText.OnFilterListener<DefaultAvatarTextItem>) filterResults -> {
if (filterResults == null) {
adapter.setItems(items);
} else if (filterResults.size() == 2) {
adapter.setItems(new ArrayList<>());
} else {
adapter.setItems(filterResults);
}
});
findViewById(R.id.clear).setOnClickListener(v -> searchEditText.setText(""));
searchBar = findViewById(R.id.searchbar);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setOnMenuItemClicked((view, item, position) -> openSearch(view));
closeButton = findViewById(R.id.close);
closeButton.setOnClickListener(v -> closeSearch());
}
Aggregations