I have an activity that uses a ViewPager for multiple Fragments, the fragments controlled by a JSONArray object. When I add a new array and update the adapter, everything updates to the correct information except the TabLayout does not reflect the change until a scroll action takes place.
If I add a Fragment when I am on the current last fragment, a new frag is created and the model updates, but the TabLayout shows the current selected as the last tab. If you do a scroll motion, you can then see the new tab, but the view update is not automatic.
Has anyone run into this and do you have any ideas how to make the TabLayout view update?
Here is the Activity and Adapter:
#EActivity(R.layout.activity_displays)
public class DisplaysActivity extends FitActivity {
#ViewById(R.id.button_right)
FitButton rightButton;
#ViewById(R.id.displays_tabview)
TabLayout tabView;
ViewPager viewPager;
JSONArray huds;
DisplaysPagerAdapter mAdapter;
#AfterViews
public void AfterViews() {
huds = StandardHuds.getStandardHudPagerData();
mAdapter = new DisplaysPagerAdapter(getSupportFragmentManager());
viewPager = (ViewPager) findViewById(R.id.displays_pager);
viewPager.setAdapter(mAdapter);
viewPager.setOffscreenPageLimit(10);
tabView.setTabMode(TabLayout.MODE_SCROLLABLE);
tabView.setupWithViewPager(viewPager);
}
#Click(R.id.button_right)
void newHud() {
addHud();
}
public class DisplaysPagerAdapter extends FragmentPagerAdapter {
public DisplaysPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if (position == 0) {
return LegendFragment_.builder().build();
} else {
JSONArray a = new JSONArray();
DisplayFragment frag = DisplayFragment_.builder().build();
try {
a = huds.getJSONArray(position - 1);
} catch (JSONException e) {
e.printStackTrace();
}
frag.setHudArray(a);
return frag;
}
}
#Override
public int getCount() {
return huds.length() + 1;
}
#Override
public CharSequence getPageTitle(int position) {
if (position == 0) {
return "Legend";
} else {
return "Display " + position;
}
}
}
public void addHud() {
JSONArray newArray = new JSONArray();
JSONArray rowArray = new JSONArray();
newArray.put(rowArray);
newArray.put(rowArray);
newArray.put(rowArray);
huds.put(newArray);
mAdapter.notifyDataSetChanged();
viewPager.refreshDrawableState();
tabView.refreshDrawableState();
}
}
xml of the ViewPager/TabLayout within the activity
<android.support.v4.view.ViewPager
android:id="#+id/displays_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footer">
<android.support.design.widget.TabLayout
android:id="#+id/displays_tabview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="?attr/colorFitBg1"
app:tabIndicatorColor="?attr/colorFitPrimary"
app:tabSelectedTextColor="?attr/colorFitPrimary" />
</android.support.v4.view.ViewPager>
I have tried to update the tabView a few different ways, but the tab is still off of the screen. Changing the max offscreen count does not affect this problem.
Let me know if you have any ideas. Thank you in advance.
Related
I got a viewPager inside it I have several fragment.
providerViewPager = (ViewPager) findViewById(R.id.viewPager);
userRequest.add(1);
fragmentPagerAdapter = new FragmentStatePagerAdapter(HomeActivity.this.getSupportFragmentManager()) {
#Override
public int getCount() {
return userRequest.size();
}
#Override
public Fragment getItem(int position) {
return MyFragment.newInstance(position, userRequest.get(position));
}
};
providerViewPager.setAdapter(fragmentPagerAdapter);
userRequest is a arrayList of int, for each item in this list I create a MyFragment.
MyFragment contain the display view for each page.
view.findViewById(R.id.mybutton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ViewPager viewPager = ((HomeActivity)getActivity()).getViewPager();
FragmentStatePagerAdapter adapter = ((HomeActivity)getActivity()).getAdapter();
ArrayList<Integer> ints = ((HomeActivity)getActivity()).getRequest();
viewPager.removeView(view);
ints.remove(getArguments().getInt("position"));
adapter.notifyDataSetChanged();
}
});
This is a onClickListener who is inside my fragment, I would like to remove this current fragment when I'm click on it.
As you can see I get the viewPager, the adapter and the arrayList from my Activity, and I try some method to remove this fragment, this work but I got some bug, for exemple if I remove an element at the middle of the view Pager I can't reach the element at the end. I would like to know if they are something much simple for remove fragment.
I solve it with this :
public void removeUserRequest(int position) {
if (position > 0) {
removeViewOnSwipe(position - 1);
} else {
removeViewOnSwipe(position);
}
}
private void removeViewOnSwipe(int position) {
userRequest.remove(position);
if (userRequest.size() == 0) {
providerViewPager.setVisibility(View.GONE);
fragmentPagerAdapter = null;
} else {
fragmentPagerAdapter = new FragmentStatePagerAdapter(HomeActivity.this.getSupportFragmentManager()) {
#Override
public int getCount() {
return userRequest.size();
}
#Override
public Fragment getItem(int position) {
return ProviderSwipeListFragment.newInstance(position, userRequest.get(position));
}
};
providerViewPager.setAdapter(fragmentPagerAdapter);
providerViewPager.setCurrentItem(position);
}
}
removeUserRequest is the method call in the Fragment.
removeViewOnSwipe : we remove the item in the userRequest list. And after that I create a new Adapter. And finally set the correct new position with
providerViewPager.setCurrentItem(position);
I try do to it without recreat a new adapter with using notifyDataSetChanged instead, but I got some bug, the previous fragment can be visible if the user scroll a lot on the end of the swipe list
I am developing an Android app. In my app, I am using TabLayout with ViewPager. I need to update the Tabs of TabLayout and its fragments programmatically when an item at the bottom navigation bar is selected. I can update the tabs of TabLayout. But the fragments of pager are not updated.
This is the issue:
As you can see in the above, tabs are changed but its fragments are not changed. List Fragment is always displayed. All the fragments are just the same with the first tab selected. I mean fragments are not changing at all.
This is my XML file for the tabs and view pager:
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:id="#+id/ma_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/ma_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
This is my whole activity:
public class MainActivity extends AppCompatActivity {
private BottomBar bottomBar;
private TabLayout topTabLayout;
private ViewPager mainViewPager;
private MainPagerAdapter pagerAdapter;
private ArrayList<Fragment> pagerFragments;
private ArrayList<String> pagerTitleList;
protected TfrApplication app;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = (TfrApplication)getApplication();
setContentView(R.layout.activity_main);
initialize();
initViews();
setUpViews();
}
private void initialize()
{
pagerFragments = new ArrayList<Fragment>();
pagerTitleList = new ArrayList<String>();
}
private void initViews()
{
bottomBar = (BottomBar)findViewById(R.id.ma_bottom_action_bar);
mainViewPager = (ViewPager)findViewById(R.id.ma_viewpager);
topTabLayout = (TabLayout)findViewById(R.id.ma_tab_layout);
}
private void setUpViews()
{
pagerAdapter = new MainPagerAdapter(getSupportFragmentManager(),pagerFragments,pagerTitleList);
mainViewPager.setAdapter(pagerAdapter);
topTabLayout.setupWithViewPager(mainViewPager);
setUpBottomBar();
}
private void clearPagerFragments()
{
if(pagerAdapter!=null && pagerFragments!=null && pagerFragments.size()>0)
{
pagerFragments.removeAll(pagerFragments);
pagerTitleList.removeAll(pagerTitleList);
pagerAdapter.notifyDataSetChanged();
}
}
private void setUpNewsPagerFragments()
{
NewsFragment latestNewsFragment = new NewsFragment();
Bundle latestNewsBundle = new Bundle();
latestNewsBundle.putInt(NewsFragment.FIELD_CATEGORY_ID,0);
latestNewsBundle.putInt(NewsFragment.FIELD_LEAGUE_ID,0);
latestNewsBundle.putInt(NewsFragment.FIELD_COUNTRY_ID,0);
latestNewsBundle.putInt(NewsFragment.FIELD_TEAM_ID,0);
latestNewsFragment.setArguments(latestNewsBundle);
pagerTitleList.add("LATEST");
pagerFragments.add(latestNewsFragment);
PrioritizedTeamsFragment teamsFragment = new PrioritizedTeamsFragment();
pagerTitleList.add("TEAMS");
pagerFragments.add(teamsFragment);
NewsFragment articlesFragment = new NewsFragment();
Bundle articlesBundle = new Bundle();
articlesBundle.putInt(NewsFragment.FIELD_CATEGORY_ID, 0);
articlesBundle.putInt(NewsFragment.FIELD_LEAGUE_ID, 0);
articlesBundle.putInt(NewsFragment.FIELD_COUNTRY_ID, 0);
articlesBundle.putInt(NewsFragment.FIELD_TEAM_ID, 0);
articlesFragment.setArguments(articlesBundle);
pagerTitleList.add("ARTICLES");
pagerFragments.add(articlesFragment);
TopFragment topFragment = new TopFragment();
pagerTitleList.add("TOP 10");
pagerFragments.add(topFragment);
}
private void setUpMatchesPagerFragments()
{
MatchesFragment matchesFragment = new MatchesFragment();
pagerTitleList.add("MATCHES");
pagerFragments.add(matchesFragment);
StatisticsFragment statisticsFragment = new StatisticsFragment();
pagerTitleList.add("STATISTICS");
pagerFragments.add(statisticsFragment);
}
private void setUpBottomBar()
{
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
#Override
public void onTabSelected(int tabId) {
switch (tabId){
case R.id.bottom_tab_news:
clearPagerFragments();
setUpNewsPagerFragments();
pagerAdapter.notifyDataSetChanged();
break;
case R.id.bottom_tab_matches:
clearPagerFragments();
setUpMatchesPagerFragments();
pagerAdapter.notifyDataSetChanged();
topTabLayout.getTabAt(0).select();
break;
case R.id.bottom_tab_meme:
Toast.makeText(getBaseContext(),"MEME",Toast.LENGTH_SHORT).show();
break;
case R.id.bottom_tab_settings:
Toast.makeText(getBaseContext(),"Settings",Toast.LENGTH_SHORT).show();
break;
}
}
});
}
}
I showed the whole activity because code the whole activity dealing with that problem. Besides, the whole activity only contains code for creating tabs, view pager and bottom bar. All are connected.
This is my view pager adapter:
public class MainPagerAdapter extends FragmentPagerAdapter {
private ArrayList<Fragment> fragmentList;
private ArrayList<String> titleList;
public MainPagerAdapter(FragmentManager fragmentManager,ArrayList<Fragment> fragmentsParam,ArrayList<String> titlesParam)
{
super(fragmentManager);
this.fragmentList = fragmentsParam;
this.titleList = titlesParam;
}
#Override
public int getCount() {
return fragmentList.size();
}
#Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public CharSequence getPageTitle(int position) {
return titleList.get(position);
}
}
Why is the content or fragments of view pager are not changed when tabs are changed? What is wrong with my code?
As you can see on bottom item selected listener I tried to set the selected fragment like this:
topTabLayout.getTabAt(0).select();
I tried this as well:
mainViewPager.setCurrentItem(0);
Both are not working.
try to add a method to swap the fragment-list and call notifyDataSetChanged() in your adapter like this:
public void notifyDataSetChanged(List<Fragment> list) {
fragmentList.removeAll();
fragmentList.addAll(list);
notifyDataSetChanged();
}
changing data in activity and call adapter.notifyDataSetChanged() may fail to update your view.You can log in getItem() to check if the adapter knows the data set has changed.
Just Check which layout you are inflating in MatchesFragment class.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.matches_fragment, container, false);
}
If your tab is set correctly, under the code where the tab is set, run this again:
mainViewPager.setAdapter(pagerAdapter);
Here is my code:
selectedTab = 0;
tabLayout.getTabAt(selectedTab).select();
viewPager.setAdapter(tabsAdapter);
I am using PagerSlidingTabStrip to show 3 tabs, with each containing list view in it.
I have a scenario where i need to add new tab at runtime, say on swipe to refresh i need to add new tab to the left end.
Below is my code to add new tab :
pagerAdapter.TABS_COUNT = 4; //global value to change the tabs count
pagerAdapter.notifyDataSetChanged();
pagerSlidingTabStrip.setViewPager(mPager);
but some times one of the tabs content becomes empty listview is not scrollable.
What is the best way that i can achieve this ?
Here is an example on how to do it, don't say it's the best way, but I wrote it in hurry https://github.com/jacktech24/pager-sliding-strip-example
First, you will need a custom adapter, here I used a simple one which is displaying only text on each fragment, but it would be easy to modify it to support normal fragments etc. mTabs in the example is:
mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
then the example
private class TestAdapter extends FragmentPagerAdapter {
private ArrayList<String> tabs = new ArrayList<>();
public TestAdapter(FragmentManager supportFragmentManager) {
super(supportFragmentManager);
}
#Override
public Fragment getItem(int position) {
Fragment frag = new ExampleFragment();
Bundle bundle = new Bundle();
bundle.putString("title", (String) getPageTitle(position));
frag.setArguments(bundle);
return frag;
}
#Override
public CharSequence getPageTitle(int position) {
return tabs.get(position);
}
#Override
public int getCount() {
return tabs.size();
}
public void addTab(String tab) {
tabs.add(tab);
notifyDataSetChanged();
mTabs.notifyDataSetChanged();
}
public void removeTab(int position) {
tabs.remove(position);
notifyDataSetChanged();
mTabs.notifyDataSetChanged();
}
}
then, it is just as simple as this:
//mAdapter is instance of your adapter
mAdapter.addTab("test 1");
mAdapter.addTab("test 2");
mAdapter.addTab("test 3");
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mAdapter.addTab("test "+(mAdapter.getCount()+1));
}
});
I was just wondering if it is the normal behaviour of viewpager and its adapter to always call the getItem() method for index 0 and 1, even if I immediately set a current position.
Here is my code:
mNewsPagerAdapter = new NewsDetailPagerAdapter(getChildFragmentManager());
mNewsPagerAdapter.updateNewsList(news);
mViewPager = (ViewPager) mView.findViewById(R.id.horizontal_view_pager);
mViewPager.setPageMargin(2);
mViewPager.setPageMarginDrawable(R.color.black);
mViewPager.setAdapter(mNewsPagerAdapter);
mViewPager.setCurrentItem(mCurrentPositionPager, false);
If I switch from my overview activity to my detail activity with this viewpager, the adapter always calls the getItem() method for position 0 and 1 and after that the getItem() method for the position of mOriginalPosition and its neighbors. I was wondering if this is the correct behaviour or if I missed something to implement it in a right way. Thanks for your help :)
Edit: Added my adapter code
public class NewsDetailPagerAdapter extends FragmentStatePagerAdapter {
private SparseArray<Fragment> mPageReferenceMap = new SparseArray<Fragment>();
private ArrayList<News> mNewsList;
public NewsDetailPagerAdapter(FragmentManager fm) {
super(fm);
}
/**
* Setzt die neuen News.
**/
public void updateNewsList(ArrayList<News> list) {
mNewsList = list;
}
#Override
public Fragment getItem(int position) {
Log.d("debug", "getItem position:" + position);
News newsItem = mNewsList.get(position);
NavigationFragment fragment = new NavigationFragment();
mPageReferenceMap.put(position, fragment);
return fragment;
}
#Override
public int getCount() {
return mNewsList.size();
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
public Fragment getFragment(int position) {
return mPageReferenceMap.get(position);
}
}
It is normal (and intelligent in my opinion).
ViewPager class has one property named mOffscreenPageLimit with default value of 1. This number determines how many pages on the left and on the right of the current page that the Viewpager will preload. For instance, you have 10 pages, current position is 5 and mOffcreenPageLimit is 1, the page at position 4 and 6 will be loaded.
You could change this property by calling this method
viewpager. setOffscreenPageLimit(int)
If you pass in an integer that is smaller than 1, it has no effect.
Yes, this is the normal behaviour of the ViewPager, because it will always try to stay ahead of the user by rendering tabs that limit with the drawing area. I personally don't recommend creating a custom ViewPager as you are almost sure to break functionality unless you really know what you are doing. Your adapter class should look something like this:
public class YourCustomPagerAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragmentList = new ArrayList<>();
private List<String> titleList = new ArrayList<>();
public WizardPagerAdapter(FragmentManager fm) {
super(fm);
}
public void addFragment(Fragment fragment, String title) {
fragmentList.add(fragment);
titleList.add(title);
}
#Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
#Override
public CharSequence getPageTitle(int position) {
super.getPageTitle(position);
return titleList.get(position);
}
#Override
public int getCount() {
return fragmentList.size();
}
}
and you should add your fragments as such:
#Override
public void onCreate(Bundle savedInstanceState) {
...
YourCustomPagerAdapter adapter = new YourCustomPagerAdapter (getSupportFragmentManager());
adapter.addFragment(FragmentOne.newInstance(), "Frag 1");
adapter.addFragment(FragmentTwo.newInstance(), "Frag 2");
viewPager.setAdapter(adapter);
...
}
Actually this is the normale behavior. In fact, as soos as you associate the ViewPager with the adapter, the adapter creates the first visibile layout (index 0) end the next one (index 1). This is done by default in the "setAdapter". Then, when you set a different position, the adapter will instantiate the fragment at the selected index, the previous one and the next one.
This is the usual ViewPager setAdapter code:
public void setAdapter(PagerAdapter adapter) {
if (mAdapter != null) {
mAdapter.setViewPagerObserver(null);
mAdapter.startUpdate(this);
for (int i = 0; i < mItems.size(); i++) {
final ItemInfo ii = mItems.get(i);
mAdapter.destroyItem(this, ii.position, ii.object);
}
mAdapter.finishUpdate(this);
mItems.clear();
removeNonDecorViews();
mCurItem = 0;
scrollTo(0, 0);
}
final PagerAdapter oldAdapter = mAdapter;
mAdapter = adapter;
mExpectedAdapterCount = 0;
if (mAdapter != null) {
if (mObserver == null) {
mObserver = new PagerObserver();
}
mAdapter.setViewPagerObserver(mObserver);
mPopulatePending = false;
final boolean wasFirstLayout = mFirstLayout;
mFirstLayout = true;
mExpectedAdapterCount = mAdapter.getCount();
if (mRestoredCurItem >= 0) {
mAdapter.restoreState(mRestoredAdapterState, mRestoredClassLoader);
setCurrentItemInternal(mRestoredCurItem, false, true);
mRestoredCurItem = -1;
mRestoredAdapterState = null;
mRestoredClassLoader = null;
} else if (!wasFirstLayout) {
populate();
} else {
requestLayout();
}
}
if (mAdapterChangeListener != null && oldAdapter != adapter) {
mAdapterChangeListener.onAdapterChanged(oldAdapter, adapter);
}
}
In order to change the ViewPager behavior, you could extend the classic ViewPager overriding the setAdapter method and set the mCurrItem to the desired position.
I hope it helped
Edit:
After different tests, we found a solution.
If the ViewPager adapter is set after ViewPager layout become visible, items 0 and 1 are load.
If you want to avoid this behavior but you can't set the adapter before the layout become visible (because you are waiting for data), than you can use this workaround:
1) Set the ViewPager visibility initially to GONE
2) After you receive all the data, you update the adapter and you set the current item value
3) Finally you set the ViewPager visibility to VISIBLE
Here you can find an example:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.detail_overview_fragment, container, false);
final int position = getArguments().getInt("position");
final ViewPager viewPager = (ViewPager) v.findViewById(R.id.viewpager);
viewPager.setVisibility(View.GONE);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
viewPager.setAdapter(new PagerAdapter(getChildFragmentManager()));
viewPager.setCurrentItem(position);
viewPager.setVisibility(View.VISIBLE);
}
},5000);
return v;
}
i think the error is the adapter:
/**
* Setzt die neuen News.
**/
public void updateNewsList(ArrayList<News> list) {
//mNewsList = list;
mNewsList.clear();
mNewsList.addAll(list);
/**
* Notifies the attached observers that the underlying data has been changed
* and any View reflecting the data set should refresh itself.
*/
this.notifyDataSetChanged();
}
error reason :this list is diffent entity for that adapter.
I'm writing my first fragment-based app and running into some heavy problems which i couldn't solve with the API or Stackoverflow.
I am using a viewPager to swipe between two lists. Each list has a header button to create a new list element (similar to the native android alarm app). The button returns currently an error message for debugging.
The problem is:
FragmentList A returns the debug message for FragmentList B
FragmentList B returns no debug message
... // The main class
public class DemoApp extends FragmentActivity implements ActionBar.TabListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
PageAdapter mPageAdapter = new PageAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mPageAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mPageAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab().setText(mPageAdapter.getPageTitle(i)).setTabListener(this));
}
}
...
My custom PageAdapter will create two list framgent objects:
public class PageAdapter extends FragmentStatePagerAdapter {
private final int NUMBER_PAGES = 2;
public PageAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if (position == 0) {
return new FoodListFragment();
} else if (position == 1){
return new LocationListFragment();
} else {
throw new IllegalArgumentException("Invalid page position: " + position);
}
}
#Override
public int getCount() {
return NUMBER_PAGES;
}
...
}
FoodListFragment snipped (The other list looks similar except the debug output) :
public class FoodListFragment extends ListFragment implements LoaderCallbacks<Cursor> {
/*
* (non-Javadoc)
*
* #see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
*/
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// add a list header with the button to create a new list item
View v = getActivity().getLayoutInflater().inflate(R.layout.list_header, null);
getListView().addHeaderView(v);
...
setListAdapter(getSomeAdapter());
// get the list header button
ImageButton createItem = (ImageButton) getActivity().findViewById(R.id.create_new_entry);
createItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e(LOG_TAG, "onclick FoodListFragment");
}
});
}
main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".DemoApp" />
</LinearLayout>
I've found the bug. In each list i was calling the same header view and same header button. The onClick method could not be clearly assigned