private void init(AttributeSet attrs) { inflate(getContext(), R.layout.searchbar, this); TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.MaterialSearchBar); iconRightResId = array.getResourceId(R.styleable.MaterialSearchBar_iconRight, -1); iconLefttResId = array.getResourceId(R.styleable.MaterialSearchBar_iconLeft, -1); hint = array.getString(R.styleable.MaterialSearchBar_hint); maxSuggestionCount = array.getInt(R.styleable.MaterialSearchBar_maxSuggestionsCount, 3); speechMode = array.getBoolean(R.styleable.MaterialSearchBar_speechMode, false); destiny = getResources().getDisplayMetrics().density; adapter = new SuggestionsAdapter(LayoutInflater.from(getContext())); adapter.setOnClickListener(this); adapter.maxSuggestionsCount = maxSuggestionCount; RecyclerView recyclerView = (RecyclerView) findViewById(R.id.mt_recycler); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); array.recycle(); searchIcon = (ImageView) findViewById(R.id.mt_search); arrowIcon = (ImageView) findViewById(R.id.mt_arrow); searchEdit = (EditText) findViewById(R.id.mt_editText); inputContainer = (LinearLayout) findViewById(R.id.inputContainer); findViewById(R.id.mt_clear).setOnClickListener(this); arrowIcon.setOnClickListener(this); searchEdit.setOnFocusChangeListener(this); setOnClickListener(this); searchEdit.setOnEditorActionListener(this); if (speechMode) searchIcon.setOnClickListener(this); setupIcons(); }
/** * Specifies the maximum number of search queries stored until the activity is destroyed * * @param maxQuery maximum queries */ public void setMaxSuggestionCount(int maxQuery) { this.maxSuggestionCount = maxQuery; adapter.maxSuggestionsCount = maxQuery; }