Closed younes0 closed 9 years ago
Thanks for your response
this is my tabs fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/tab_title"/>
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</LinearLayout>
And this is the tab fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/list"
android:choiceMode="multipleChoice"
android:dividerHeight="1dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Why is this TextView over the PagerSlidingTabStrip
view?
Sorry that was for testing purposes. When I'm adding that TextView, it doesn't produce the mentionned error.
This is what I get when I put the TextView below Tab / Fragment switching works but tab title isn't shown as you can see you (no problem related to the adapter as it returns title)
Are you trying to use a custom tab? What are you actually trying to do?
I don't have any custom tab, it is required?
No, but I thought it was the feature you were using. Can you explain into detail what you are doing? It seems to be a problem in your code. Paste the adapter.
public class FilterFragment extends Fragment {
protected ViewPager pager;
protected MaterialTabHost tabHost;
protected MyPagerAdapter adapter;
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_filter_tabs, container, false);
ButterKnife.inject(this, view);
// Initialize the ViewPager and set an adapter
ViewPager pager = (ViewPager) view.findViewById(R.id.viewpager);
pager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager()));
// Bind the tabs to the ViewPager
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
tabs.setViewPager(pager);
return view;
}
public class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return "hello";
}
@Override
public int getCount() {
return 2;
}
@Override
public Fragment getItem(int position) {
return new FilterOriginsFragment();
}
}
}
public class FilterOriginsFragment extends Fragment {
public FilterOriginsFragment() {}
protected View mView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_filter_origins, container, false);
setHasOptionsMenu(true);
/* .. */
return mView;
}
}
You have 2 fragments but just 1 Title?
@jpardogo this is for debugging purposes
You are not getting hello hello? when does it crash?
Are you using gradle? Or you added the library yourself as a library project?
It crashes as I instanciate the fragment with a custom navigation drawer: https://github.com/neokree/MaterialNavigationDrawer
The image you saw is when I add
<TextView android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/tab_title"/>
Which I don't want since I'm fine with the default tab layout.. When I don't add that, it crashes
I'm using gradle
You are using a ViewPager with fragments inside a fragment:
1.I would not complicate that much the app architecture, unless it is strictly necessary.
getChildFragmentManager()
instead of getActivity().getSupportFragmentManager()
I am not sure that it is the problem but at least , worth to mention. Give it a try and let me know
Thanks for your help...
Do you have any layout in your project called tab.xml?
http://stackoverflow.com/questions/16204667/nosuchfielderror-on-findviewbyid
"If you have one project working as a library that declares some id in a given XML file, then your main project redefines that XML, the original id is gone, but you won't see the error until run time."
"The solution may be: The name of xml file is repeated, eg:a.xml is in your library project, at the same time, a.xml is in your main project. so, please change one of the xml name."
Did you redefined tab.xml? tab.xml
I have checked that SO question: I don't have any tab.xml
or any duplicate xml filename file or any ressource called tab_title
wait... now I'm doubtful, I still have that other similar library in gradle. Keep you informed in 5 min
I have actually implemented the ViewPager inside a fragment last week for the same reason you are doing it. And It worked fine... I am really curious about this error.... Don't you see any difference between the example code and yours? Did you try to create a fresh new project and implement a simplify example to see what could be happening and find the error?
If you have more libraries about tabs it could be that 2 of the resources are being overwriten. Two tab.xml layouts.
You're right: I still had 'it.neokree:MaterialTabs:0.11' as dependencie which uses the same XML ids ! May I suggest you to namespace the XML ids
Thank you so much for your time
could you please explain to me this error? This doesn't happen when I add an textView with tab_title id, docs don't mention to add it although, and still I get other issue, the view is blank...