Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a TextWatcher to EditText inside ActionBarSherlock having MenuItem.SHOW_AS_ACTION_ALWAYS
    text
    copied!<p>I'm using ActionBarSherlock, I want to display an EditText in it with MenuItem.SHOW_AS_ACTION_ALWAYS. It takes the full width of the bar and shows as desired. But I am running into trouble trying to add a TextWatcher to it.</p> <p>So based on the accepted answer here: <a href="http://goo.gl/ite6h" rel="nofollow">http://goo.gl/ite6h</a> I write:</p> <pre><code> EditText search; public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { menu.add(0, 1, 1, R.string.inlineSearch).setIcon(R.drawable.action_search).setActionView(search).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); return super.onCreateOptionsMenu(menu); } private TextWatcher filterTextWatcher = new TextWatcher() { public void afterTextChanged(Editable s) { Log.e("TextWatcher","after"); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { Log.e("TextWatcher","before"); } public void onTextChanged(CharSequence s, int start, int before, int count) { Log.e("TextWatcher","onText"); } }; @Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { Log.e("onOptions",""+item.getItemId()); // Line 150 switch (item.getItemId()) { case 1: search = (EditText) item.getActionView(); search.addTextChangedListener(filterTextWatcher); search.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } return true; } </code></pre> <p>Problem is, line 150 is never reached (no log) and nothing the listener is not added to the search (EditText).</p> <p>Could anyone point me in the right direction?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload