MoGa
MoGa

Reputation: 655

Custom layout inside FragmentGridPagerAdapter

I am trying to add a custom layout page within cards.

Here: https://developer.android.com/training/wearables/ui/2d-picker.html

explains that CardFragment can easily add a card by:

CardFragment fragment = CardFragment.create(title, text, page.iconRes);

now if I decided I want to have a custom layout, how do I add it instead of creating a CardFragment?

Check this image:

enter image description here

The third page is a full screen custom layout. How can I achieve this?

Upvotes: 1

Views: 1348

Answers (3)

Leonardo
Leonardo

Reputation: 228

On getFragment(int row, int col) method from your FragmentGridPagerAdapter class, you can create as many fragments as you want.

you just need to test your row/col values in order to instantiate your fragment class in the correct position.

In your case, something like this:

public Fragment getFragment(int row, int col) {

    Fragment fragment;
    if (row == 0 && col == 2) {
        fragment = new YourFullScreenFragment();
    } else {
        fragment = CardFragment.create(title, text, page.iconRes);
    }

    return fragment;

}

Cheers

Upvotes: 2

Michał Tajchert
Michał Tajchert

Reputation: 10383

CardFrame is probably that one that you are looking for - it very similar to CardFragment but you can implement your own layout to it. Also as matiash pointed you can use any fragment that you like in such structure.

Upvotes: 0

matiash
matiash

Reputation: 55370

FragmentGridPagerAdapter can actually support any subclass of Fragment that you need to use. CardFragment is just a convenience for a standard wearable layout.

So, you can just create a custom Fragment with a simple layout (such as a full-size ImageView) and return it for the appropriate page index.

Upvotes: 3

Related Questions