0

enter image description here

In this image I have a list.

What I want is to change the view of this Fragment to the image given below.

Image 2

On the header, I want to add a search button. By clicking on the button the second image layout will appear and and by clicking the button again, it will fire a web service that returns with the response.

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98

2 Answers2

0

First of all add the search button.Initialize it in your main activity.In your project I suggest you to do with a single onclicklistner and a longclicklistner.For double tap you have to initialize a gesture. I can provide you a code for any approaches but I strongly suggest you go with the first one.Reply mi accordingly I will provide you a code.

Akshay
  • 1,161
  • 1
  • 12
  • 33
0

I think that what you are actually asking is "How to get a reference of the ViewPager's Fragment and do something with that". If this is the case, you can have a look here, you see, its a very common and not that easy problem. One way to solve ot correctly (providing that you are already using a FragmentStateAdapter) is doing something like the following:

In your activity:

  private CustomFragment mHomeFragment;
  private CustomFragment mOfferFragment;
  private CustomFragment mFavoriteFragment;
  private CustomFragment mInfoFragment;

and then, in your adapter

 @Override
    public Fragment getItem(int position) {
        return CustomFragment.newInstance(position, null);

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
        // save the appropriate reference depending on position
        switch (position) {
            case 0:
                mHomeFragment = (CustomFragment) createdFragment;
                break;
            case 1:
                mOfferFragment = (CustomFragment) createdFragment;
                break;
            case 2:
                mFavoriteFragment = (CustomFragment) createdFragment;
                break;
            case 3:
                mInfoFragment = (CustomFragment) createdFragment;
                break;
        }
        return createdFragment;
    }

Doing that, it will allow you to do:

mViewPager.setCurrentItem(1);
mOfferFragment.doSomething();

in your parrent Activity

Community
  • 1
  • 1
Nikiforos
  • 154
  • 11