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 8657369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:30:15+00:00 2026-06-12T15:30:15+00:00

Several tries to ask this question in #android-dev (irc) and hours of searching, but

  • 0

Several tries to ask this question in #android-dev (irc) and hours of searching, but I still don’t have a solution to this problem.

I’m currently working on the search-function in my android music player. I’m using the amazing ActionBarSherlock to provide support for older android versions.

My Problem is the following:
When the user clicks the search menu/action button, the actionView of the clicked action should be expanded, and a new Fragment (the searchFragment) should be shown instead of the currently active one.
However when i’m attempting to do this, the actionView doesn’t expand.

I’ve tried to expand the actionView, without adding the SearchFragment, and in that case the actionView DOES expand. However the combination seems impossible.

Here’s my code:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item != null) {
        if (item.getItemId() == R.id.collectionactivity_search_menu_button) {
            item.expandActionView();
            mTabsAdapter.replace(new SearchFragment(), false);
            return true;
        }
    }
    return false;
}

/**
 * Replaces the view pager fragment at specified position.
 */
public void replace(int position, Fragment newFragment, boolean isBackAction) {
    // Get currently active fragment.
    ArrayList<Fragment> fragmentsStack = mFragments.get(position);
    Fragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
    if (currentFragment == null) {
        return;
    }
    // Replace the fragment using a transaction.
    this.startUpdate(mViewPager);
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.attach(newFragment).remove(currentFragment).commit();
    if (isBackAction == true)
        fragmentsStack.remove(currentFragment);
    else
        fragmentsStack.add(newFragment);
    this.notifyDataSetChanged();
    this.finishUpdate(mViewPager);
}

The mTabsAdapter.replace(…) method replaces the currently shown Fragment with the one in the first parameter. In Addition the fragment is being added to a custom backStack.
Replacing the Fragment before or after expanding the View didn’t make any difference.

Hopefully somebody is able to help me 🙂
thanks in advance!

  • 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-12T15:30:16+00:00Added an answer on June 12, 2026 at 3:30 pm

    I found out what the problem was caused by.

    My mTabsAdapter.replace(..) method was calling notifyDataSetChanged();. So everytime I replaced the fragment, onPrepareOptionsMenu was being called, resulting in the search action button being removed and added again, thus resulting in the actionView being collapsed.

    The solution to this is to fix my onPrepareOptionsMenu, so the actionView will be expanded again, whenever onPrepareOptionsMenu is called and the actionView was expanded before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry to ask this question again but I tried several solutions on stackoverflow and
I do not know if this the correct forum to ask this question but
I have, of course, read several questions with exactly this asked, but I have
Sorry to ask this question, but it's now day 3 I try to solve
Okay, this is like the 5th time I have had to ask this question,
I tried several solutions found on other posts but still having problems to autoresize
I have tried several of the solutions I have seen out here, but am
I have tried several things so far, but I haven't had much luck yet.
I ask this question in the hope of collecting all the incompatible changes/bugfixes in
I am not very experienced with rails, but I have used it for several

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.