How can I lock paging in fragment activity of viewpager for fragment swipe.I'm performing some operations using progressbar in one fragment.While progressing progressbar fragment gets changes because of swipe action.so while progessing progressbar I want to stop swiping.How to do this?is there any solution??
activity.xml file-
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainFragmentActivity" >
<android.support.v4.view.PagerTitleStrip
android:id="#+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#drawable/title"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
fragment activity-
public class MainFragmentActivity extends FragmentActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
private Context mContext;
private PagerTitleStrip pt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(),mContext);
mContext=this;
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
pt=(PagerTitleStrip) findViewById(R.id.pager_title_strip);
}
SectionsPagerAdapter-
public class SectionsPagerAdapter extends FragmentPagerAdapter {
Context mContext;
Fragment fragment;
public SectionsPagerAdapter(FragmentManager fm, Context context) {
super(fm);
mContext=context;
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
if(position==0){
fragment = new SelectItem();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
}
if(position==1){
fragment = new culation();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
}
if(position==2){
fragment = new GraphDisplay();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0 :
return "Select item";
case 1:
return "Calculation";
case 2:
return "Graph";
}
return null;
}
}
Try setting clickable to false:
mViewPager.setClickable(false);
If that works what you can do is create a function in activity to disable swipe event on view pager and call that function in fragment in event of progress bar show and a function to enable it.
Subclass ViewPager and override onTouch event for example:
EDIT
public class NonSwipeableViewPager extends ViewPager {
private boolean lock;
public void lock(){
lock=true;
}
public void unlock(){
lock=false;
}
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if(lock)
return false;else{
return super.onTouchEvent(event);
}
}
}
reference:
How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?
I found a simple way to do this, with its adapter.
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
/**
* Created by paul.boldijar on 2/24/2015.
*/
public class SimpleFragmentAdapter extends FragmentPagerAdapter {
private Fragment[] fragments;
private boolean locked = false;
private int lockedIndex;
public void setLocked(boolean locked, int page) {
this.locked = locked;
lockedIndex = page;
notifyDataSetChanged();
}
public SimpleFragmentAdapter(FragmentManager fm, Fragment[] fragments) {
super(fm);
this.fragments = fragments;
}
#Override
public Fragment getItem(int position) {
if (locked) return fragments[lockedIndex];
return fragments[position];
}
#Override
public int getCount() {
if (locked) return 1;
return fragments.length;
}
}
If you want to lock your fragment to a page, just call fragment.setLocked(true,page);
Where page is the index of the page you want to lock.
Based on the solution by Paul, I modified it to support displaying titles as well
public static class MainPagerAdapter extends FragmentStatePagerAdapter {
private Fragment[] fragments;
private String[] titles;
private boolean locked = false;
private int lockedIndex;
public MainPagerAdapter(FragmentManager fm, Fragment[] fragments, String[] titles) {
super(fm);
this.fragments = fragments;
this.titles = titles;
}
public void setLocked(boolean locked, int page) {
this.locked = locked;
lockedIndex = page;
notifyDataSetChanged();
}
#Override
public Fragment getItem(int position) {
if (locked) return fragments[lockedIndex];
return fragments[position];
}
#Override
public int getCount() {
if (locked) return 1;
return fragments.length;
}
#Override
public CharSequence getPageTitle(int position) {
if (locked) return titles[lockedIndex];
return titles[position];
}
}
The way I use it is to say
Fragment[] fragments = {//Create fragment objects here...};
String[] titles = getResources().getStringArray(R.array.tabs);
MainPagerAdapter adapter = new MainPagerAdapter(getSupportFragmentManager(), fragments, titles);
adapter.setLocked(true, 0);
mPager.setAdapter(adapter);
You can use this View:
https://github.com/mr-sarsarabi/lockableViewPager
It lets you lock the swipe gesture with a method: viewPager.setSwipeLocked(true);
Related
All my fragments are android.support.v4.app.Fragment and the Viewpager extends FragmentStatePagerAdapter which also uses android.support.v4.app.Fragment.
I have a Fragment class which extends PreferenceFragment that I want to add in my Viewpager with my other two fragments.
How can I accomplish this?
Here's my ViewPager
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<String> mFragmentsTitle = new ArrayList<>();
public void addFragment(Fragment fragment, String title){
mFragments.add(fragment);
mFragmentsTitle.add(title);
}
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
#Override
public int getCount() {
return mFragments.size();
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentsTitle.get(position);
}
}
Here's what I have in my PreferenceFragment
public class GameNotesFragment extends PreferenceFragment {
public GameNotesFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_game_notes, container, false);
return view;
}
}
When I try to add it in:
mSectionsPagerAdapter.addFragment(new GameNotesFragment(), "Note");
It gives me
Wrong firt argument com.example.fragments.GameNotesFragment', required: 'android.support.v4.app.Fragment'
PreferenceFragment extends the platform variant of the Fragment class. What you need is a PreferenceFragmentCompat that extends the support lib variant of Fragment (mind the different packages).
The support preferences require additional package(s) in your gradle file:
implementation 'com.android.support:preference-v7:27.1.0'
implementation 'com.android.support:preference-v14:27.1.0'
Also, while you're at it, make sure to check out the bug fix lib I created for the support preferences' common (and pretty annoying) bugs.
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<String> mFragmentsTitle = new ArrayList<>();
public void addFragment(Fragment fragment, String title){
mFragments.add(fragment);
mFragmentsTitle.add(title);
}
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public android.support.v4.app.Fragment getItem(int position) {
android.support.v4.app.Fragment f = null;
if (position == 0) {
f = new GameNotesFragment();
}
if (position == 1) {
f = new GameNotesFragment(); //replace your fragment 2
}
if (position == 2) {
f = new GameNotesFragment();//replace your fragment 3
}
return f;
}
#Override
public int getCount() {
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getResources().getString(R.string.name1);
case 1:
return getResources().getString(R.string.name2);
case 2:
return getResources().getString(R.string.name3);
return null;
}
}
and in activity:
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(MainActivity.this.getSupportFragmentManager());
tabLayout = v1.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
In my app i am using pager adapter to load 2 fragments, the fragments are not getting loaded and view pager remains null. Where i am going wrong? Any help will be appreciated
Here is my code
I am setting this adapter to my view pager from activity
public class ViewPagerActivityAdapter extends PagerAdapter {
ArrayList<Fragment> tablist;
public ViewPagerActivityAdapter(ArrayList<Fragment> tablist) {
this.tablist = tablist;
}
#Override
public int getCount() {
return tablist.size();
}
#Override
public boolean isViewFromObject(View view, Object object) {
return false;
}
#Override
public Object instantiateItem(ViewGroup collection, int position) {
return null;
}
#Override
public void destroyItem(ViewGroup collection, int position, Object view) {
}
}
Activity Part
private ViewPagerActivityAdapter viewPagerAdapter;
private ArrayList<Fragment> fragments_faq;
fragments_faq = new ArrayList<>();
FragmentOne frag1 = new FragmentOne();
tablayout.addTab(tablayout.newTab().setText("fragone"));
fragments_faq.add(frag1);
FragmentTwo frag2 = new FragmentTwo();
tablayout.addTab(tablayout.newTab().setText("fragtwo"));
fragments_faq.add(frag2);
private void setPagerAdapter() {
viewPagerAdapter = new ViewPagerActivityAdapter(fragments_faq);
viewpager.setAdapter(viewPagerAdapter);
viewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout));
viewpager.setOffscreenPageLimit(2);
tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewpager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
#Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
for details check this gist
https://gist.github.com/vinay6kr/33359c3f3b0e9f28e33bd383b01e9d9f
if you want to show fragments in viewpager you should use FragmentStatePagerAdapter
public class MyViewPagerAdapter extends FragmentStatePagerAdapter {
CharSequence Titles[];
public MyViewPagerAdapter(FragmentManager fm, CharSequence mTitles[]) {
super(fm);
this.Titles = mTitles;
}
#Override
public Fragment getItem(int position) {
if (position == 0)
return new Fragment1().getInstance();
else if (position == 1)
return new Fragment2().getInstance();
}
#Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
#Override
public int getCount() {
return Titles.length;
}
}
and to Set them
void setUpTabs() {
String Titles[] = {"Frag1","Frag2"};
MyViewPagerAdapter adapter = new MyViewPagerAdapter(this.getSupportFragmentManager(), Titles);
viewPager.setAdapter(adapter);
}
You can try like adapter look like
class ViewPagerActivityAdapter extends FragmentPagerAdapter {
// fragments to instantiate in the viewpager
private List<Fragment> fragments;
// constructor
public ViewPagerActivityAdapter(FragmentManager fm,List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
// return access to fragment from position, required override
#Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
// number of fragments in list, required override
#Override
public int getCount() {
return this.fragments.size();
}
}
Add Fragment
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this,
FragmentOne.class.getName()));
fragments.add(Fragment.instantiate(this,
FragmentTwo.class.getName()));
Add to view Pager
ViewPagerActivityAdapter mPagerAdapter;
this.mPagerAdapter = new ViewPagerActivityAdapter(
super.getSupportFragmentManager(), fragments);
mPager = (ViewPager) super.findViewById(R.id.pager);
mPager.setAdapter(this.mPagerAdapter);
You should use FragmentPagerAdapter or FragmentStatePagerAdapter for this.Here is sample code.
public class ViewPagerActivityAdapter extends FragmentPagerAdapter {
ArrayList<Fragment> tablist;
public ViewPagerActivityAdapter(ArrayList<Fragment> tablist) {
this.tablist = tablist;
}
#Override
public int getCount() {
return tablist.size();
}
#Override
public Fragment getItem(int position) {
return tablist.get(position);
}
}
My host activity has a viewpager with two fragments A and B.My activity code looks like this:
public class MainActivity extends AppCompatActivity implements
OnDataLoadedListener {
private ViewPager pager;
private MyPagerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
adapter = new MyPagerAdapter(getSupportFragmentManager());
pager.setAdapter(adapter);
final int pageMargin = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
.getDisplayMetrics());
pager.setPageMargin(pageMargin);
tabLayout.setupWithViewPager(pager);
}
public class MyPagerAdapter extends FragmentPagerAdapter {
private final String[] TITLES = { "A",
"B" };
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
#Override
public int getCount() {
return TITLES.length;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return A.getInstance();
case 1:
return B.getInstance();
}
return null;
}
}
public Fragment findFragmentByPosition(int position) {
return getSupportFragmentManager().findFragmentByTag(
"android:switcher:" + pager.getId() + ":"
+ adapter.getItemId(position));
}
Now when activity start viewpager get populated with fragment properly and I try to access fragmentby using following code:
if (AFragment == null)
AFragment = (A) findFragmentByPosition(0);
if (BFragment == null)
BFragment = (B) findFragmentByPosition(1);
But AFragment and BFragment always contains null.I have read other simmilar question but it didn't help either.I need access to fragments as I want to call some methods defined in fragment from host activity.
Code to get an instance of fragment:
public static AFragment getInstance() {
AFragment fragment = new AFragment();
return fragment;
}
I'm think that the problem is that you need to move the method to the Adapter, because you need the original instance of the FragmentManager :
public class MyPagerAdapter extends FragmentPagerAdapter {
FragmentManager fm;
private final String[] TITLES = { "A",
"B" };
public MyPagerAdapter (FragmentManager fm) {
super(fm);
this.fm = fm;
}
#Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
#Override
public int getCount() {
return TITLES.length;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return A.getInstance();
case 1:
return B.getInstance();
}
return null;
}
public Fragment findFragmentByPosition(int position, int pagerId) {
return fm.findFragmentByTag(
"android:switcher:" + pagerId + ":"
+ getItemId(position));
}
}
So now you can call:
adapter.findFragmentByPosition(position, pager.getId());
I've looked at so many questions here that I don't even know exactly what I'm looking for.
I have a simple app that uses a ViewPager. It has 3 tabs and there is a fragment for each tab. The first fragment contains a ListView. I want to be able to click on an element in the ListView and have that bring me to a different fragment.
So basically I want to remove the fragment that contained the ListView once an element is clicked and add in a new fragment. I've tried to do this in a few different ways with none working.
The last thing I tried was to edit the TabsPageAdapter once an element was clicked which pretty much works except when I press the back button it exits the app. Also it doesn't seem like the cleanest way of doing this.
TabsPagerAdapter
public class TabsPagerAdapter extends FragmentStatePagerAdapter {
SherlockFragment mf;
TalkingPointsFragment tpf;
ContactFragment gf;
int mode = 0;
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
mf = new CanvassFragment();
tpf = new TalkingPointsFragment();
gf = new ContactFragment();
}
public TabsPagerAdapter(FragmentManager fm, int mode)
{
super(fm);
if(mode == 0)
{
mf = new CanvassFragment();
tpf = new TalkingPointsFragment();
gf = new ContactFragment();
}
else if(mode == 1)
{
mf = new ContactFragment();
tpf = new TalkingPointsFragment();
gf = new ContactFragment();
}
}
#Override
public SherlockFragment getItem(int index) {
switch (index) {
case 0:
return mf;
case 1:
return tpf;
case 2:
return gf;
}
return null;
}
#Override
public int getCount() {
// get item count - equal to number of tabs
return 3;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object)
{
}
}
The onclick code:
ViewPager viewp = (ViewPager) getActivity().findViewById(R.id.pager);
TabsPagerAdapter mAdapter = new TabsPagerAdapter(getActivity().getSupportFragmentManager(),1);
viewp.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
layout_main.xml
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:actionBarTabStyle="#drawable/actionbar_tab_indicator">
I FragmentStatePagerAdapter too and when a user selects map from the ActionBar, I add the GoogleMapsFragment on top of the FragmentStatePagerAdapter:
// create a new map
mapsFragment = GoogleMapFragment.newInstance();
// Then we add it using a FragmentTransaction.
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.add(android.R.id.content, mapsFragment,
FRAGMENT_MAP_TAG);
fragmentTransaction.commit();
For your case you would probably need to add it to the backstack too, which I have not because in my app the user has to navigate back using the ActionBar.
Thought this approach could work for you too when a user selects an item from your list.
Of course this has the disadvantage of not being able to use the FragmentStatePagerAdapter until the user navigates back. So I am not sure wether that would be acceptable for your app.
Ok, so this took a bit more code that I imagined. Hope you get the idea:
public class MainClass extends FragmentActivity implements CanvassCallback {
// save a single reference to ViewPager and TabsPagerAdapter
private ViewPager mViewPager;
private TabsPagerAdapter mAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.mViewPager = (ViewPager) findViewById(R.id.pager);
this.mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), this);
mViewPager.setAdapter(mAdapter);
...
}
// from the CanvassCallback interface
public void itemSelected() {
mAdapter.canvassSelected();
mAdapter.notifyDataSetChanged();
}
#Override
public void onBackPressed() {
if (mViewPager.getCurrentItem() == 0 && mAdapter.isCanvassSelected() {
mAdapter.canvassSelected();
mAdapter.notifyDataSetChanged();
}
else {
super.onBackPressed();
}
}
}
Mockup of your CanvassFragment showing the callback
public class CanvassFragment extends SherlockFragment {
public interface CanvassCallback {
public void itemSelected();
}
private CanvassCallback canvassCallback;
public void setCanvassCallback(CanvassCallback canvassCallback) {
this.canvassCallback = canvassCallback;
}
...
// The onClick of your item
private void onClick() {
// notify your activity that an item was selected
canvassCallback.itemSelected();
}
}
The registeredFragments are not strictly needed but I think it provides some value if your need to call methoods on your Fragment from activity.
public class TabsPagerAdapter extends FragmentStatePagerAdapter {
// see upvoted answer from http://stackoverflow.com/questions/8785221/retrieve-a-fragment-from-a-viewpager
SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
private boolean canvassSelected = false;
private CanvassCallback canvassCallback;
public TabsPagerAdapter(FragmentManager fm, CanvassCallback canvassCallback) {
super(fm);
this.canvassCallback = canvassCallback;
}
public void canvassSelected() {
canvassSelected = !canvassSelected;
}
public boolean isCanvassSelected() {
return canvassSelected;
}
#Override
public SherlockFragment getItem(int index) {
switch (index) {
case 0:
if (canvassSelected)
return new ContactFragment();
CanvassFragment canvassFragment = new CanvassFragment();
// this ensures that your Activity gets notified when an item is clicked
canvassFragment.setCanvassCallback(canvassCallback);
return canvassFragment;
case 1:
return new TalkingPointsFragment();
case 2:
return new ContactFragment();
}
return null;
}
#Override
public int getCount() {
// get item count - equal to number of tabs
return 3;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Log.d(TAG, "instantiateItem " + position);
Fragment fragment = (Fragment) super.instantiateItem(container, position);
registeredFragments.put(position, fragment);
return fragment;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
Log.d(TAG, "destroyItem " + position);
registeredFragments.remove(position);
super.destroyItem(container, position, object);
}
}
I have a FragmentList with some items. If I click an item the appropriate Fragment will open which contains a Viewpager. No problem so far but if I go back to the List and click the item again the method getItem(int position) is not called anymore.
Here a link with a similar problem:
Display fragment viewpager within a fragment
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.activity_fragment_runtime, container, false);
mViewPager = (ViewPager) view.findViewById(R.id.pager);
indicator = (TitlePageIndicator) view.findViewById(R.id.indicator);
MyFragmentPagerAdapter mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getActivity().getSupportFragmentManager());
mViewPager.setAdapter(mMyFragmentPagerAdapter);
indicator.setViewPager(mViewPager);
return view;
}
class MyFragmentPagerAdapter extends FragmentStatePagerAdapter implements TitleProvider {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public String getTitle(int position) {
return muxbusTitles[position];
}
#Override
public Fragment getItem(int location) {
return muxbusFragmentList.get(location);
}
#Override
public int getCount() {
return muxbusTitles.length;
}
}
return view;
}
Edit:
If someone is interested,the solution was to extends from PagerAdapter instead of FragmentStatePagerAdpater because the Viewpager is already in a Fragment..
I did have similar problem and after scratching my head for quite some time i made an my own understanding (assumption) that ViewPager is keeping the reference of its child fragments into memory even the hosted Fragment or Activity is destroyed (didn't tested with Activity). So i wrote this method freeFragmentsFromViewPager(). You need to call it from onDestroy() of your Fragment.
/**
* This method free the child fragments from ViewPager as ViewPager keeps the reference
* of child fragments into memory and next time when you again come to visit view pager it won't show the fragment layout
* because it has the reference to the fragment whilst the fragment's view was already destroyed.
*/
private void freeFragmentsFromViewPager()
{
for(int i = 0; i < TabsFragmentPagerAdapter.fragments.length; i++)
{
Fragment fragment = TabsFragmentPagerAdapter.fragments[i];
if(fragment != null)
{
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.remove(fragment);
fragmentTransaction.commit();
TabsFragmentPagerAdapter.fragments[i] = null;
}
}
}
And this is my Adapter code
public class TabsFragmentPagerAdapter extends FragmentPagerAdapter
{
public static final int NUM_TABS = 3;
public static Fragment[] fragments = new Fragment[NUM_TABS];
public TabsFragmentPagerAdapter(FragmentManager fm)
{
super(fm);
}
#Override
public Fragment getItem(int position)
{
Log.e("TabsFragmentPagerAdapter", "getItem");
Fragment fragment = TabsFragmentFactory.newInstace(position);
fragments[position] = fragment;
return fragment;
}
#Override
public int getCount()
{
return NUM_TABS;
}
#Override
public CharSequence getPageTitle(int position)
{
return TabsFragmentFactory.getName(position);
}