V
V
Vadim Popov2018-07-03 20:01:30
Java
Vadim Popov, 2018-07-03 20:01:30

How to track a click on the search view icon?

I use search view from android.widget library

final SearchView searchView = findViewById(R.id.search_view);
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            Message.showMessage(searchView.getContext(),"test");
            return false;
        }
        });

Message.showMessage is my analogue of the standard Toast for displaying a test message. I can't understand which method is responsible for listening to the magnifying glass button click event on the virtual keyboard?
5b3babe4c06a9340710897.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Popov, 2018-07-04
@vadimpopov94

I found a solution for myself, maybe it will be useful for someone

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(final String query) {
        //вызовется при нажатии на лупу на клавиатуре
        return false;
    }

    @Override
    public boolean onQueryTextChange(final String newText) {
        //вызовется при изменении ведённого текста
        return true;
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question