0

Based on the default "Fixed Tabs + Swipe" activity in the ADT, I have a FragmentActivity with a FragmentPagerAdapter.

The FragementPagerAdapter is very simple (just returns a certain fragment based on the called position) and at the moment the FragmentActivity itself is also pretty default from the 'example' code Eclipse provides. The 'interesting' parts are attached at the end, but this is how it looks (obviously simplified for question-purposes)

Now in one of the various fragments, I have a button that should show some information and a picture / pictures: something that does not really belong in the tabbed-view.

What is the best method for this?

I thought about either just starting a new activity, but this is discouraged in favor of building with fragments, so I discarded that option. Then I could just make a 'random' fragment to show, but I'm not sure how to implement that in regard to the pager -> this might actually be the best way.

What I could come up with was to show a DialogFragment. I've actually implemented this like so:

First create a DialogFragment with this onCreateView:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    LinearLayout v = (LinearLayout) inflater.inflate(R.layout.entry, container, false);
    //set image
    return v;
}

and show it like so:

fragment.show(getSupportFragmentManager(), "dialog");

the xml is a simple linearLayout that was suggested on stackoverflow.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:minWidth="1000dp"  
    android:minHeight="1000dp"> 

    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/image_desc" 
         />

 </LinearLayout> 

The problem here is that while this is shown allright, it seems that there is something (the title bar for the pager? not sure) is added above the picture:

It's hard to see, but I believe it is directly in line with the bottom of the pager-fragment-titles, so I seem to have 'inherited' some features?

Current base-code

From the onCreate in the FragmentActivity

setContentView(R.layout.activity_main);
...

mSectionsPagerAdapter = new SectionsPagerAdapter(
    getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);

The SectionsPagerAdapter is an inner-class FragmentPagerAdapter that returns some fragments, nothing interesting

The activity_main, again pretty standard:

<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=".MainActivity" >

<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->

    <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="#555555"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" />

</android.support.v4.view.ViewPager>
Nanne
  • 64,065
  • 16
  • 119
  • 163
  • The thing you're seing above the picture is the default dialog titlebar. You can remove it by calling getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); in your dialogFragments onCreateView, before you inflate your view – Jakob Harteg Nov 03 '13 at 14:10
  • Woah. that was easy :D, thanks. that's one thing taken care of at least :) . Care to add what you think is the best method to do this? is this a good way, with the dialog? – Nanne Nov 03 '13 at 14:16

1 Answers1

1

Using a dialogFragment does in my opinion seem like a good way to go, and it is certainly one of the easiest.

Additionally you could make your dialogFragment fullscreen, if that is appropriate, like this: Create a custom Dialog style in values/styles.xml

<!-- DIALOG STYLE -->
<style name="Your.Dialog" parent="android:Theme.Holo.Dialog" >
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

and then set the style where you call the fragment, like this:

    myDialogFragment dialog = new myDialogFragment ();
    dialog.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Your_Dialog );
    dialog.show(getSupportFragmentManager(), "fragment_tag");
Jakob Harteg
  • 9,587
  • 15
  • 56
  • 78