use of org.odk.collect.android.widgets.utilities.SearchQueryViewModel in project collect by opendatakit.
the class BaseSelectListWidget method setUpSearchBox.
private void setUpSearchBox() {
ComponentActivity activity = (ComponentActivity) getContext();
SearchQueryViewModel searchQueryViewModel = new ViewModelProvider(activity).get(SearchQueryViewModel.class);
binding.choicesSearchBox.setVisibility(View.VISIBLE);
binding.choicesSearchBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getAnswerFontSize());
binding.choicesSearchBox.addTextChangedListener(new TextWatcher() {
private String oldText = "";
@Override
public void afterTextChanged(Editable s) {
if (!s.toString().equals(oldText)) {
recyclerViewAdapter.getFilter().filter(s.toString());
searchQueryViewModel.setQuery(getFormEntryPrompt().getIndex().toString(), s.toString());
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
oldText = s.toString();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
binding.choicesSearchBox.setText(searchQueryViewModel.getQuery(getFormEntryPrompt().getIndex().toString()));
}
Aggregations