Add sub activites with tab activiy [closed] - android

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to add different activities with tab activity, for example i have many tab like home, add music, add video etc, home tab attach with home activity. In home activity there is a button , after clicking this button page will go to another activity, So how can i see tab to this activity.

As Anrijs said TabActivity has been deprecated on android so use the support design library's TabLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabTextAppearance="#style/TabTextStyle"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Then create a ViewPager
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Then implement a Fragment for each of your activities
And follow this tutorial to make everything work nicely

TabActivity is was deprecated in API level 13. You should consider using ViewPager and TabLayout.
Add Design Support library to your project build.gradle:
dependencies {
compile 'com.android.support:design:22.2.0'
}
Add TabLayout and ViewPager to you
<?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">
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
<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" />
Create fragment:
// In this case, the fragment displays simple text based on the page
public class PageFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
public static PageFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
PageFragment fragment = new PageFragment();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_page, container, false);
TextView textView = (TextView) view;
textView.setText("Fragment #" + mPage);
return view;
}
}
Create FragmentPageAdapter:
public class SampleFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
private Context context;
public SampleFragmentPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
#Override
public Fragment getItem(int position) {
return PageFragment.newInstance(position + 1);
}
#Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return tabTitles[position];
}
}
Set up Activity:
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the ViewPager and set it's PagerAdapter so that it can display items
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(new SampleFragmentPagerAdapter(getSupportFragmentManager(),
MainActivity.this));
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
}
}
Source: https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout

Related

How to replace the first Fragment of ViewPager with another Fragment and be at the same position of the previous Fragment

I'm using TabLayout and ViewPager in my app . I have 2 tabs in my ViewPager . I have the main 2 Fragment for the 2 tabs .
The first Fragment is like a form when user click submit , another Fragment appears to user and so on and be at the same position of the previous Fragment. I want to do that in the first Fragment (first position of my ViewPager) and keep the state of the previous fragment when I click back button . I hope that I posted my question in a right way
Here is my ViewPager
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".UI.Fragments.OnlineBookingModule.OnlineBookingFragment">
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabLayout"
app:tabIndicatorColor="#color/colorPrimary"
android:background="#color/bg_nav"/>
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/viewPager"/>
</LinearLayout>
Here is My Pager Adapter
public class BookingPagerAdapter extends FragmentStatePagerAdapter {
private Context context;
public BookingPagerAdapter(#NonNull FragmentManager fm, int behavior,Context context) {
super(fm, behavior);
this.context=context;
}
#NonNull
#Override
public Fragment getItem(int position) {
if(position==0)
return new NewBookingFragment();
else
return new FutureBookingFragment();
}
#Override
public int getCount() {
return 2;
}
#Nullable
#Override
public CharSequence getPageTitle(int position) {
if(position==0)
return context.getString(R.string.new_booking);
else
return context.getString(R.string.future_booking);
}
}
Here is how I setup my viewPager in my Fragment
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_online_booking, container, false);
tabLayout = view.findViewById(R.id.tabLayout);
viewPager = view.findViewById(R.id.viewPager);
Preferences preferences = new Preferences();
preferences.saveSmallDays(getActivity(),0);
preferences.saveBigDays(getActivity(),0);
assert getFragmentManager() != null;
pagerAdapter = new BookingPagerAdapter(getFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,getActivity());
tabLayout.setupWithViewPager(viewPager);
viewPager.setAdapter(pagerAdapter);
return view;
}

How to implement the avatar selection screen like this in android without using any library?

this is my first question here. I am trying implement similar avatar selection screen for my college project. I searched almost everywhere and it seems like it can be done using viewpager. I tried but cant achieve similar effect. I have problem is showing all child in at the same time. and also i cant able to achieve the select avatar scaled in high and rest in low. Please help me out, i want to implement quickly as possible without using any library because i want to understand how it can be implemented without it as of now. Thanks in advance.
I have tried to create a viewpager with 3 images. This is my implementation.
MainActivity.java with MyPagerAdapter
public class MainActivity extends AppCompatActivity {
FragmentPagerAdapter pagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.myViewPager);
pagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter);
}
public static class MyPagerAdapter extends FragmentPagerAdapter {
private static int NUM_ITEMS = 3;
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return FirstFragment.newInstance(R.drawable.a);
case 1:
return SecondFragment.newInstance(R.drawable.b);
case 2:
return ThirdFragment.newInstance(R.drawable.c);
default:
return null;
}
}
#Override
public int getCount() {
return NUM_ITEMS;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<android.support.v4.view.ViewPager
android:id="#+id/myViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
</RelativeLayout>
I have 3 Fragements. This is one of the fragement.
FirstFragment.java
public class FirstFragment extends Fragment {
private int image;
public FirstFragment() {
}
public static FirstFragment newInstance(int resImage) {
FirstFragment fragment = new FirstFragment();
Bundle args = new Bundle();
args.putInt("image", resImage);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
image = getArguments().getInt("image", 0);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_first, container, false);
ImageView imageView = (ImageView) view.findViewById(R.id.firstImg);
imageView.setImageResource(image);
return view;
}
}
This is fragment_first.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TODO: Update blank fragment layout -->
<ImageView
android:id="#+id/firstImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>

TabLayout - ViewPager - Fragment

I have a problem with my ViewPager and fragments it contains. I have 2 menus (A and B), my homepage is directly A. When I click on a menu B fragment which contains a TabLayout, which contains a ViewPager himself three fragments (each contains a simple TextView with Lorem ipsum).
The 3 fragments of ViewPager are correct but if I click on the menu A and I click again on the menu B I do not have any content. Nothing on the fragments 1 and 2 against with the 3rd still has the text and if I return to fragment 1 reads income (for nothing against the fragment 2).
Here is my code :
Menu B (FragmentTabLayout)
public class TabLayoutFragment extends Fragment {
private static final String ARG_TEXT = "ARG_TEXT";
private static final String ARG_COLOR = "ARG_COLOR";
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
public TabLayoutFragment() {
// Required empty public constructor
}
public static TabLayoutFragment newInstance(String text, int color) {
Bundle args = new Bundle();
args.putString(ARG_TEXT, text);
args.putInt(ARG_COLOR, color);
TabLayoutFragment tabLayoutFragment = new TabLayoutFragment();
tabLayoutFragment.setArguments(args);
return tabLayoutFragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_tab_layout, container, false);
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
toolbar.setBackgroundColor(getArguments().getInt(ARG_COLOR));
toolbar.setTitle(getArguments().getString(ARG_TEXT));
viewPager = (ViewPager) view.findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) view.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setBackgroundColor(getArguments().getInt(ARG_COLOR));
tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
return view;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.tab_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getActivity().getSupportFragmentManager());
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
//private final List<TabFragment> mFragmentList = new ArrayList<>();
//private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return TabFragment.newInstance("Fragment 2-1");
case 1:
return TabFragment.newInstance("Fragment 2-2");
case 2:
return TabFragment.newInstance("Fragment 2-3");
default:
return TabFragment.newInstance("Fragment Default");
}
}
#Override
public int getCount() {
//return mFragmentList.size();
return 3;
}
}
}
Fragment in ViewPager :
public class TabFragment extends Fragment {
private static final String ARG_TEXT = "ARG_TEXT";
private TextView tv;
public TabFragment() {
// Required empty public constructor
}
public static TabFragment newInstance(String text) {
Bundle args = new Bundle();
args.putString(ARG_TEXT, text);
TabFragment tabFragment= new TabFragment();
tabFragment.setArguments(args);
return tabFragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_tab, container, false);
tv = (TextView) view.findViewById(R.id.tv);
return view;
}
}
Layout FragmentTabLayout :
<android.support.design.widget.CoordinatorLayout
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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.design.widget.CoordinatorLayout>
layout tabFragment :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.application.myapplication.TabFragment">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<TextView
android:id="#+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/lorem_ipsum"
/>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
you can extends your ViewPagerAdapter
FragmentStatePagerAdapter
instead of
FragmentPagerAdapter
I have same issue and it works for me.
In my Opinion the better approach is you should try using childFragmentManager for your nested fragments
Here is the simple example:
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getActivity().getChildFragmentManager());
viewPager.setAdapter(adapter);
}
Hopefully it will solve your issue.

Tabs of TabLayout not showing

I have a main activity, which hosts a fragment, which in turn hosts a TabLayout (with a ViewPager). The tab bar is shown, baut the tabs themselves are not shown.
Here is my code in the main activity for displaying the host fragment:
Fragment fragment = new BMITabsFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack(Constants.BMI_TABS_FRAGMENT).commit();
Here is my the Fragment which hosts the TabLayout, which is BMITabsFragment (s.a.):
public class BMITabsFragment extends Fragment {
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Get the ViewPager and set it's PagerAdapter so that it can display items
ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager);
viewPager.setAdapter(new BMIFragmentPagerAdapter(getActivity().getSupportFragmentManager(),
getActivity()));
// Give the TabLayout the ViewPager
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_bmitabs, container, false);
return view;
}
...
}
This is my FragmentPagerAdapter:
public class BMIFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 2;
private FragmentManager fragmentManager;
private Context context;
public BMIFragmentPagerAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
this.fragmentManager = fm;
}
public BMIFragmentPagerAdapter(FragmentManager fm) {
super(fm);
fragmentManager = fm;
}
#Override
public CharSequence getPageTitle(int position) {
String[] pageTitles = context.getResources().getStringArray(R.array.page_titles_array);
return pageTitles[position];
}
#Override
public Fragment getItem(int position) {
SharedPreferences prefs = context.getSharedPreferences(Constants.SHARED_PREFS_FILE, 0);
long patientId = prefs.getLong(Constants.SELECTED_PATIENT_ID, 1);
Fragment fragment = null;
switch (position){
case 0:
return BMITabelleFragment.newInstance(patientId);
case 1:
return BMIChartFragment.newInstance(patientId);
default:
return BMITabelleFragment.newInstance(patientId);
}
}
#Override
public int getCount() {
return PAGE_COUNT;
}
}
And this is the fragment_bmitabs.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
<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>
My code is based on the Google Android Guide at https://github.com/codepath/android_guides/wiki/Google-Play-Style-Tabs-using-TabLayout
What I am missing here?
Note: I am using AppCompatActivity and the support libraries v4 & v7 and the com:android:support:design library
This fixed it for me:
tabLayout.post(new Runnable() {
#Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
https://code.google.com/p/android/issues/detail?id=180462
Set tab icons after setupWithViewPager()
private void setTabs {
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();
}
private void setupTabIcons() {
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
}
like #Nathaniel Ford said,this should a bug, I change to use design library 23.0.1。google fixed it,so change build.gradle to compile 'com.android.support:design:23.0.1'. ps:you also must change your compileSdkVersionto 23
None of the other answers worked for me, I tried all of them
However, this one did: TabLayout not showing tabs after adding navigation bar
According to that answer, you have to enclose your TabLayout in a AppBarLayout. Why? Who knows. But at least it works.
Example Code (taken from that post):
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:id="#+id/appBarLayout2">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabLayout2"
app:tabMode="fixed"
app:tabGravity="fill"
></android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:id="#+id/viewPager2"
android:layout_below="#+id/appBarLayout2">
</android.support.v4.view.ViewPager>
If you are using android:tabPadding attribute in Tablayout of xml file,remove it.
You can use FragmentStatePagerAdapter instead of FragmentPagerAdapter.
It may help you.
If someone, in future, works with TabLayout along with ViewPager2 and faces same issue. Just add .attach(); at end of new TabLayoutMediator().
new TabLayoutMediator(tabLayoutRef, viewPager2Ref, (tab, position) -> tab.setText("Tab No. "+position)).attach();

ViewPager with Fragment with different layouts

I am new to using ViewPagers and Fragments together. My app has a ListView on startup, which bring the user to a details view based on a id that is passed. The problem I'm running into is that the details view has a different layout then the list view. The ViewPager is on the intial screen's layout, so when using the ViewPager the layout retains the inital layout, which is basically just a status bar at the bottom, which should go away when the user is on the details view.
This is what I have so far:
Main.xml (initial layout on startup, with a status bar)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<!-- Footer -->
<TextView
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<!-- Footer -->
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#id/status
/>
</RelativeLayout>
Main.class
public class Main extends SherlockFragmentActivity
{
private static int NUMBER_OF_PAGES;
private ViewPager mViewPager;
private MyFragmentPagerAdapter mMyFragmentPagerAdapter;
private static List<Fragment> fragments;
#Override
public void onCreate(final Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
mViewPager = (ViewPager)findViewById(R.id.viewpager);
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mMyFragmentPagerAdapter);
NUMBER_OF_PAGES = 5;
fragments = new ArrayList<Fragment>();
fragments.add(new ListingFragment()); //initial screen that just a ListView
fragments.add(DetailsFragment.newInstance(1));
fragments.add(DetailsFragment.newInstance(2));
fragments.add(DetailsFragment.newInstance(3));
fragments.add(DetailsFragment.newInstance(4));
}
private static class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int index) {
return fragments.get(index);
}
#Override
public int getCount() {
return NUMBER_OF_PAGES;
}
}
}
Details.xml (details view with no status bar)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
</RelativeLayout>
DetailsFragment.class
public class DetailsFragment extends SherlockFragmentActivity
{
private int detailId;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public void onActivityCreated(final Bundle icicle)
{
super.onActivityCreated(icicle);
}
public static DetailsFragment newInstance(int id) {
DetailsFragment lf = new DetailsFragment();
Bundle bundle = new Bundle();
bundle.putInt("id", id);
lf.setArguments(bundle);
return lf;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.details, container, false);
detailId = getArguments().getInt("id");
return view;
}
}
The ViewPager is on the intial screen's layout, so when using the
ViewPager the layout retains the inital layout, which is basically
just a status bar at the bottom, which should go away when the user is
on the details view.
Then don't put it in the main layout file. If the status is tied to the first fragment then it belong in its view, especially if the DetailsFragment doesn't need to show that status TextView.
So remove the status TextView from main.xml and add it to the layout file used in the ListingFragment. If ListingFragment extends ListFragment then create a layout file which contains a ListView with the id(android:id="#android:id/list") + the status TextView and inflate this layout file in the onCreateView.

Categories

Resources