Search in sources :

Example 1 with SearchQueryViewModel

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()));
}
Also used : ComponentActivity(androidx.activity.ComponentActivity) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SearchQueryViewModel(org.odk.collect.android.widgets.utilities.SearchQueryViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 ComponentActivity (androidx.activity.ComponentActivity)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 SearchQueryViewModel (org.odk.collect.android.widgets.utilities.SearchQueryViewModel)1