Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to focus and show soft keyboard when a EditText is shown in action bar?
    primarykey
    data
    text
    <p>I used ActionBarSherlock to create ActionBar it has a search button that shows an <code>AutoCompleteEditText</code> (<code>SHOW_AS_COLLAPSIBLE_ACTION_VIEW</code>) When Search button is clicked, <code>EditText</code> is shown, i want <code>EditText</code> to get focus and thus show the Soft Keyboard, as it's expanded this is the code </p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.activity_main, menu); boolean isLight = true; // Add Search button int menuItemId = menu .add("Search") .setIcon( isLight ? R.drawable.ic_search_inverse : R.drawable.ic_search) .setActionView(R.layout.collapsible_edittext) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW) .getItemId(); // Add Search Topic (Sub Menu) SubMenu subMenu1 = menu.addSubMenu("Topic"); subMenu1.add(Menu.NONE, 10, 0, "All Topics"); subMenu1.add(Menu.NONE, 11, 1, "Adult"); subMenu1.add(Menu.NONE, 12, 2, "Pediatric"); subMenu1.add(Menu.NONE, 13, 13, "Drug"); MenuItem subMenu1Item = subMenu1.getItem(); subMenu1Item.setIcon(R.drawable.abs__ic_menu_moreoverflow_holo_light); subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); searchBar = (AutoCompleteTextView) menu.findItem(menuItemId) .getActionView().findViewById(R.id.etSearch); setSearchSettings(searchMenuID); // get instance of Search Button searchWidgetItem = menu.findItem(menuItemId); searchBar .setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { // Perform a Search performSearch(v.getText().toString(), (searchMenuID &lt; 0) ? 3 : searchMenuID); imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); // Collapse the ActionView (Search Bar) searchWidgetItem.collapseActionView(); // Clear the TextEdit v.setText(""); return true; } return false; } }); return true; } </code></pre> <p>I tried to set a <code>OnFocusChangeListener</code> on EditText and show Soft Keboard if it has focus, but it didnt worked:</p> <pre><code>searchBar.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_FORCED); } } }); </code></pre> <p>How to do this ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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