in Actionbar sherlock, add tab throw: commit already called - android

I'm trying to use ActionBarSherlock for tab view in android. It's only a demo project with 3 tabs, each tab just show a fragment which contains a textview. This is my MainActivitycode:
public class MainActivity extends SherlockFragmentActivity {
private ActionBar mActionBar;
private Tab tab1;
private Tab tab2;
private Tab tab3;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
mActionBar = getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
tab1 = mActionBar.newTab().setText("TAB1");
tab2 = mActionBar.newTab().setText("TAB2");
tab3 = mActionBar.newTab().setText("TAB3");
tab1.setTabListener(new TabSelectListener(FragmentTest
.newInstance("Fragment1"), R.id.container));
tab2.setTabListener(new TabSelectListener(FragmentTest
.newInstance("Fragment2"), R.id.container));
tab3.setTabListener(new TabSelectListener(FragmentTest
.newInstance("Fragment3"), R.id.container));
mActionBar.addTab(tab1);
mActionBar.addTab(tab2);
mActionBar.addTab(tab3);
}
private class TabSelectListener implements TabListener {
private SherlockFragment mFragment;
private int resId;
public TabSelectListener(SherlockFragment fragment, int resId) {
mFragment = fragment;
this.resId = resId;
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Log.e("Listener", "onTabSelected");
ft.replace(resId, mFragment).commit();
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
Log.e("Listener", "onTabUnselected");
// ft.remove(mFragment).commit();
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Log.e("Listener", "onTabReselected");
}
}
}
//This is my FragmentTest
public class FragmentTest extends SherlockFragment {
private String name;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
TextView textView = (TextView) view.findViewById(R.id.tvText);
textView.setText("" + name);
return view;
}
public static SherlockFragment newInstance(String s) {
return new FragmentTest().setName(s);
}
public String getName() {
return name;
}
public FragmentTest setName(String name) {
this.name = name;
return this;
}
}
The code above will cause my application force close with: commit already called error. I searched for many tutorials but no clue. Can anyone explain and fix it for me? Thank you very much!

I know this is a old question but since no answer is given, here it is. Change:
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Log.e("Listener", "onTabSelected");
ft.replace(resId, mFragment).commit();
}
To
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Log.e("Listener", "onTabSelected");
ft.replace(resId, mFragment);
}
The FragmentTransaction will automatically get commited, thus explicitely calling .commit() will throw the error you encounter.

Related

How to disable/enable the ActionBar.TabListener on some condition

I have implemented ActionBar.TabListener with viewpager. Now I want to disable tab click for some condition
I have stopped swipe using TouchListner but want to do same for Tab Click.
Here is my code.
MainActivity.java
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
ActionBar actionBar;
ViewPager viewPager;
String check ="";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.pager);
FragmentManager fragmentManager = getSupportFragmentManager();
viewPager.setAdapter(new MyAdpter(fragmentManager));
viewPager.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
if ("".equals(check)) {
return true;
}
return false;
}
});
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = actionBar.newTab();
tab1.setText("Tab 1");
tab1.setTabListener(this);
ActionBar.Tab tab2 = actionBar.newTab();
tab2.setText("Tab 2");
tab2.setTabListener(this);
ActionBar.Tab tab3 = actionBar.newTab();
tab3.setText("Tab 3");
tab3.setTabListener(this);
actionBar.addTab(tab1);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
viewPager.setCurrentItem(2, false);
}
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
}
MyAdpter.java
class MyAdpter extends FragmentPagerAdapter{
public MyAdpter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
Fragment fragment = null;
if(position==0){
fragment = new FragmentA();
}
if(position==1){
fragment = new FragmentB();
}
if(position==2){
fragment = new FragmentC();
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
}
FragmentA.java
public class FragmentA extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_a , container,false);
}
}
FragmentB/FragmentC are similar to FragmentA
activity_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="match_parent" >
</android.support.v4.view.ViewPager>
ScreenShot
you can do something like this..
in OnCheckedChanged listener for checkbox, you can specify which tabs are enable..
just by doing
// to enable
tabLayout.getChildAt(position).setEnabled(true);
// or to disable
tabLayout.getChildAt(position).setClickable(false);.
use this property to enable or disable clicks on tab.

How to add child fragment without ActionBar and swipe to class fragment

I have Fragment MainActivity class with ActionBar and swipe which work well.
Acording to action user the class FragmentA,FragmentB,FragmentC show in the scren.
How can I add child fragment without ActionBar and without swipe from FragmentA class
public class FragmentA extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_a,container,false);
}
}
so from FragmentA I will have
-- FragmentAA
-- FragmentAB
Many Thanks For any help.
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
ViewPager viewPager=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager= (ViewPager) findViewById(R.id.pager);
final ActionBar actionBar=getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
addTabs(actionBar);
viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int i, float v, int i2) {
}
#Override
public void onPageSelected(int i) {
actionBar.setSelectedNavigationItem(i);
}
#Override
public void onPageScrollStateChanged(int i) {
}
});
}
private void addTabs(ActionBar actionBar)
{
ActionBar.Tab tab1=actionBar.newTab();
tab1.setText("Tab 1");
tab1.setTabListener(this);
ActionBar.Tab tab2=actionBar.newTab();
tab2.setText("Tab 2");
tab2.setTabListener(this);
ActionBar.Tab tab3=actionBar.newTab();
tab3.setText("Tab 3");
tab3.setTabListener(this);
actionBar.addTab(tab1);
actionBar.addTab(tab2);
actionBar.addTab(tab3);
}
#Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
}
class MyAdapter extends FragmentStatePagerAdapter
{
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
Fragment fragment=null;
if(i==0)
{
fragment=new FragmentA();
}
if(i==1)
{
fragment=new FragmentB();
}
if(i==2)
{
fragment=new FragmentC();
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
}

how to renew the fragment when click at the tabs

I would like to create a new fragment every time when I click its tab.
I tried to get the tab and to create a fragment. But it doesn't seem to work.
Here is my code.
Main Activity
public class MainActivity extends FragmentActivity {
private static ViewPager viewPager;
private static TabsPagerAdapter mAdapter;
private static ActionBar actionBar;
// Tab titles
private String[] tabs = { "TopRated", "Hots", "NEW"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
//actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(tabListener));
}
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
actionBar.setSelectedNavigationItem(position);
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
static ActionBar.TabListener tabListener = new ActionBar.TabListener() {
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
};
TabsPagerAdapter
public class TabsPagerAdapter extends FragmentPagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
#Override
public Fragment getItem(int index) {
switch (index) {
case 0:
return new TopRatedFragment();
case 1:
return new HotStoryFragment();
case 2:
return new AllClassFragment();
}
return null;
}
#Override
public int getCount() {
// get item count - equal to number of tabs
return 3;
}
One of the fragments
public class HotStoryFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("Refresh_F","(2) HotStory");
View rootView = inflater.inflate(R.layout.fragment_hotstory, container, false);
TextView tvStudy = (TextView)rootView.findViewById(R.id.text);
return rootView;
}

Selecting tabs not working

currently i have tabs in my activity, i can swipe between the tabs easily.
But here's a bug:
I Can't select a tab!
Here i'm on the new tab.
If i click on upcomming i will get this
I Will need to swype in order to see the content of upcoming!
Why is this happening?
Here's is my codes:
public class Taby extends SherlockFragmentActivity {
FragmentTransaction transaction;
static ViewPager mViewPager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Fragment tabOneFragment = new TabOne();
Fragment tabTwoFragment = new TabTwo();
PagerAdapter mPagerAdapter = new PagerAdapter(
getSupportFragmentManager());
mPagerAdapter.addFragment(tabOneFragment);
mPagerAdapter.addFragment(tabTwoFragment);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mPagerAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setCurrentItem(0);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
getSupportActionBar().setSelectedNavigationItem(
position);
}
});
ActionBar ab = getSupportActionBar();
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
com.actionbarsherlock.app.ActionBar.Tab tab1 = ab
.newTab()
.setText("New")
.setTabListener(
new TabListener<TabOne>(this, "tabone", TabOne.class));
com.actionbarsherlock.app.ActionBar.Tab tab2 = ab
.newTab()
.setText("Upcoming")
.setTabListener(
new TabListener<TabTwo>(this, "tabtwo", TabTwo.class));
ab.addTab(tab1);
ab.addTab(tab2);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.like, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
case R.id.facebooklike:
String facebookScheme = "fb://profile/" + "192346130896055";
Intent facebookIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(facebookScheme));
startActivity(facebookIntent);
break;
}
return true;
}
#SuppressLint("NewApi")
public static class TabListener<T extends Fragment> implements
ActionBar.TabListener {
private Fragment mFragment;
private final Activity mActivity;
private final String mTag;
private final Class<T> mClass;
public TabListener(Activity activity, String tag, Class<T> clz) {
mActivity = activity;
mTag = tag;
mClass = clz;
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (mFragment == null) {
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.add(android.R.id.content, mFragment, mTag);
} else {
ft.attach(mFragment);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null) {
ft.detach(mFragment);
}
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
public void onTabReselected(Tab arg0,
android.app.FragmentTransaction arg1) {
}
#SuppressLint("NewApi")
public void onTabSelected(Tab arg0, android.app.FragmentTransaction arg1) {
mViewPager.setCurrentItem(arg0.getPosition());
}
public void onTabUnselected(Tab arg0,
android.app.FragmentTransaction arg1) {
}
#Override
public void onTabSelected(com.actionbarsherlock.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabUnselected(
com.actionbarsherlock.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
#Override
public void onTabReselected(
com.actionbarsherlock.app.ActionBar.Tab tab,
FragmentTransaction ft) {
// TODO Auto-generated method stub
}
}
public class PagerAdapter extends FragmentPagerAdapter {
private final ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
public PagerAdapter(FragmentManager manager) {
super(manager);
}
public void addFragment(Fragment fragment) {
mFragments.add(fragment);
notifyDataSetChanged();
}
#Override
public int getCount() {
return mFragments.size();
}
#Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
}
mViewPager.setCurrentItem(position); inside the onPageSelected() like that:
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
getSupportActionBar().setSelectedNavigationItem(
position);
mViewPager.setCurrentItem(position);
}
});

How to get which fragment has been selected

I am creating a tab application, using fragments.
I have successfully created tabs, but now I need to create an object when a specific fragment is selected. e.g. When I select SettingsTab I need to call a function that is defined in Test class. and similarly destroy
// SettingsTab
package com.example.sensorspositioningn;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class SettingsTab extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.settingstab, container, false);
}
}
Here is the code in mainActivity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appContext = getApplicationContext();
//ActionBar
ActionBar actionbar = getActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab Tab1= actionbar.newTab().setText("Tab1");
ActionBar.Tab Tab2= actionbar.newTab().setText("Tab2");
ActionBar.Tab Tab3= actionbar.newTab().setText("Tab3");
ActionBar.Tab SettingsTab = actionbar.newTab().setText("Settings");
Fragment Tab1F= new Tab1();
Fragment Tab2F= new Tab2();
Fragment Tab3F= new Tab3();
Fragment mSettingsFragment = new SettingsTab();
Tab1.setTabListener(new MyTabsListener(Tab1F));
Tab1.setTabListener(new MyTabsListener(Tab2F));
Tab1.setTabListener(new MyTabsListener(Tab3F));
SettingsTab.setTabListener(new MyTabsListener(mSettingsFragment));
actionbar.addTab(Tab1);
actionbar.addTab(Tab2);
actionbar.addTab(Tab3);
actionbar.addTab(SettingsTab);
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("tab", getActionBar().getSelectedNavigationIndex());
}
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(MainActivity.appContext, "Reselected!", Toast.LENGTH_LONG).show();
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
}
In your ActionBar.TabListener you can do this - (I'm assuming that you need the object to be in the Activity)
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(MainActivity.appContext, "Reselected!", Toast.LENGTH_LONG).show();
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
if(fragment instanceof SettingsTab) {
// Create your object, call your function
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
if(fragment instanceof SettingsTab) {
// Destroy your object
}
}
}
Try this
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
if(fragment instanceof SettingsTab){
doSettingsMethod();
}
if(fragment instanceof Tab1){
doOtherMethod1();
}
if(fragment instanceof Tab2){
doOtherMethod2();
}
if(fragment instanceof Tab3){
doOtherMethod3();
}
}
Also you may change TabListener class in this way. As for me it's a better design.
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
private final Runnable onSelect;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
this.onSelect = null;
}
public MyTabsListener(Fragment fragment, Runnable onSelect) {
this.fragment = fragment;
this.onSelect = onSelect;
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
Toast.makeText(MainActivity.appContext, "Reselected!", Toast.LENGTH_LONG).show();
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
if(onSelect != null){
fragment.getActivity().runOnUiThread(onSelect);
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
}
The only official source I found to this was on the developer site:
http://developer.android.com/training/implementing-navigation/lateral.html
They simply put arguments for each created fragment, and read the arguments when the fragments get selected.
By default if you select a tab it will be highlighted. If you want to select Explicitly means use the given commented code under onTabSelected(TabLayout.Tab tab) with your specified tab index position. This code will explains about change fragment on tab selected position using viewpager.
public class GalleryFragment extends Fragment implements TabLayout.OnTabSelectedListener
{
private ViewPager viewPager;public ViewPagerAdapter adapter;private TabLayout tabLayout;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_gallery, container, false);
viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
adapter = new ViewPagerAdapter(getChildFragmentManager());
adapter.addFragment(new PaymentCardFragment(), "PAYMENT CARDS");
adapter.addFragment(new LoyaltyCardFragment(), "LOYALTY CARDS");
viewPager.setAdapter(adapter);
tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setOnTabSelectedListener(this);
}
#Override
public void onTabSelected(TabLayout.Tab tab) {
//This will be called 2nd when you select a tab or swipe using viewpager
final int position = tab.getPosition();
Log.i("card", "Tablayout pos: " + position);
//TabLayout.Tab tabdata=tabLayout.getTabAt(position);
//tabdata.select();
tabLayout.post(new Runnable() {
#Override
public void run() {
if (position == 0) {
PaymentCardFragment paymentCardFragment = getPaymentCardFragment();
if (paymentCardFragment != null) {
VerticalViewpager vp = paymentCardFragment.mypager;
if(vp!=null)
{
//vp.setCurrentItem(position,true);
vp.setCurrentItem(vp.getAdapter().getCount()-1,true);
}
}
}
if (position == 1) {
LoyaltyCardFragment loyaltyCardFragment = getLoyaltyCardFragment();
if (loyaltyCardFragment != null) {
VerticalViewpager vp = loyaltyCardFragment.mypager;
if(vp!=null)
{
vp.setCurrentItem(position);
}
}
}
}
});
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
//This will be called 1st when you select a tab or swipe using viewpager
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
//This will be called only when you select the already selected tab(Ex: selecting 3rd tab again and again)
}
private PaymentCardFragment getLoyaltyCardFragment() {
Fragment f = adapter.mFragmentList.get(viewPager.getCurrentItem());
if(f instanceof PaymentCardFragment)
{
return (PaymentCardFragment) f;
}
return null;
}
private LoyaltyCardFragment getPaymentCardFragment() {
Fragment f = adapter.mFragmentList.get(viewPager.getCurrentItem());
if(f instanceof LoyaltyCardFragment)
{
return (LoyaltyCardFragment) f;
}
return null;
}
class ViewPagerAdapter extends FragmentPagerAdapter {
public List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
}
}

Categories

Resources