Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:14:35+00:00 2026-06-13T02:14:35+00:00

I used ActionBarSherlock to create ActionBar it has a search button that shows an

  • 0

I used ActionBarSherlock to create ActionBar
it has a search button that shows an AutoCompleteEditText (SHOW_AS_COLLAPSIBLE_ACTION_VIEW)
When Search button is clicked, EditText is shown, i want EditText to get focus and thus show the Soft Keyboard, as it’s expanded
this is the 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 < 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;
}

I tried to set a OnFocusChangeListener on EditText and show Soft Keboard if it has focus, but it didnt worked:

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);
                }
            }
        });

How to do this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:14:37+00:00Added an answer on June 13, 2026 at 2:14 am

    Found the Solution:

    searchWidgetItem.setOnActionExpandListener(new OnActionExpandListener() {
    
                @Override
                public boolean onMenuItemActionExpand(MenuItem item) {
                    searchBar.post(new Runnable() {
                        @Override
                        public void run() {
                            searchBar.requestFocus();
                            imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.showSoftInput(searchBar,
                                    InputMethodManager.SHOW_IMPLICIT);
                        }
                    });
                    return true;
                }
    
                @Override
                public boolean onMenuItemActionCollapse(MenuItem item) {
    
                    return true;
                }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used the phonegap website to create an IPA file. Now I want to
I used TOAD for oracle 11g, I want to create an insert script from
I used ActionBarSherlock to get some Holo Themed Tabs and an ActionBar on my
I've used this code to place a collapsible View (EditText) in ActionBarSherlock : public
Never used a cache like this before. The problem is that I want to
I've just used ActionBar Sherlock to implement the android action bar on pre 3.0
i used this code: List<string> lists=new List<string>(apple,orange,banana,apple,mang0,orange); string names; names=lists.Distinct() is that correct?
i'm using actionbar sherlock/fragments with my app my problem is that i need to
I know that it can used Fragment in ActionBarSharlock3.x,because It contain the support package
Used the create unit tests tool in Visual Studio and obviously it tries to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.