Guest User

Untitled

a guest
Jan 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import android.content.Context;
  2. import android.support.v7.widget.SearchView;
  3. import android.util.AttributeSet;
  4.  
  5. public class EmptySubmitSearchView extends SearchView {
  6.  
  7. /*
  8. * Created by: Jens Klingenberg (jensklingenberg.de)
  9. * GPLv3
  10. *
  11. * //This SearchView gets triggered even when the query submit is empty
  12. *
  13. * */
  14.  
  15. SearchView.SearchAutoComplete mSearchSrcTextView;
  16. OnQueryTextListener listener;
  17.  
  18. public EmptySubmitSearchView(Context context) {
  19. super(context);
  20. }
  21.  
  22. public EmptySubmitSearchView(Context context, AttributeSet attrs) {
  23. super(context, attrs);
  24. }
  25.  
  26. public EmptySubmitSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
  27. super(context, attrs, defStyleAttr);
  28. }
  29.  
  30. @Override public void setOnQueryTextListener(OnQueryTextListener listener) {
  31. super.setOnQueryTextListener(listener);
  32. this.listener = listener;
  33. mSearchSrcTextView = this.findViewById(android.support.v7.appcompat.R.id.search_src_text);
  34. mSearchSrcTextView.setOnEditorActionListener((textView, i, keyEvent) -> {
  35. if (listener != null) {
  36. listener.onQueryTextSubmit(getQuery().toString());
  37. }
  38. return true;
  39. });
  40. }
  41. }
Add Comment
Please, Sign In to add comment