astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

Refresh the Activity on Swipe Tab in Android? #249

Open saqlainmediasoft opened 9 years ago

saqlainmediasoft commented 9 years ago

i want to know that how we can Refresh the Activity using Tab Swipe feature in android. below is my code:

        //Click & Sliding Control on Tabs

        tabs.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
        {
            // This method will be invoked when a new page becomes selected
            @Override
            public void onPageSelected(int position)
            {
                // When swiping between pages OR select the corresponding tab
                switch (position)
                {
                    default:
                    case 0:
                        Tab1 tab1 = new Tab1();  
                        adapter.notifyDataSetChanged();
                        break;
                }
            }
        });

My TAB1 Activity Code is below: Please have a look as well:

public class Tab1 extends Fragment {

    Context mContext;
    private GridView mGridView;
    public static String[] eatFoodyImages = {
            "https://media.giphy.com/media/T7VuyIFl3jimI/giphy.gif",
            "http://www.goodwp.com/large/201210/24514.jpg",
            "http://www.goodwp.com/mini/201210/24499.jpg",
            "https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg",
            "http://i.imgur.com/rFLNqWI.jpg",
            "http://i.imgur.com/C9pBVt7.jpg",
            "http://i.imgur.com/rT5vXE1.jpg",
            "http://i.imgur.com/aIy5R2k.jpg",
            "http://i.imgur.com/MoJs9pT.jpg",
            "http://i.imgur.com/S963yEM.jpg",
            "http://i.imgur.com/rLR2cyc.jpg",
            "http://i.imgur.com/SEPdUIx.jpg",
            "http://i.imgur.com/aC9OjaM.jpg",
            "http://i.imgur.com/76Jfv9b.jpg",
            "http://i.imgur.com/fUX7EIB.jpg",
            "http://i.imgur.com/syELajx.jpg",
            "http://i.imgur.com/COzBnru.jpg",
            "http://i.imgur.com/Z3QjilA.jpg",
    };

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.tab_1, container, false);
        mGridView = (GridView)v.findViewById(R.id.grid_view);

        mContext=getActivity().getApplicationContext();
        mGridView.setAdapter(new ImageAdapter(mContext, eatFoodyImages));

        //Click Event on Images in GridView
        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(mContext, "Pic" + (position + 1) +" Selected", Toast.LENGTH_SHORT).show();
            }
        });
        return v;
    }
}

i am using onPageSelected which is working fine when click on Tab or Swipe the Tabs. For example if i display the TOAST then it works fine. just i don't know how to call Activity. Actually i just wants to perform Refresh as i have Gridview which contains the Pictures.