MikkoP
MikkoP

Reputation: 5092

ActionBar tabs and multi-fragment layout with ViewPager

I have an application that uses ActionBar tabs for navigation. With these tabs I use FragmentPagerAdapter with a ViewPager in the layout.

I have configured these in my application's main Activity. In there I add a page change listener for the ViewPager and change tabs regarding to position. I also do it the other way around when a tab is pressed. This is all fine.

Then I have the contents I have in the tabs. Both of them extend Fragment class. The first one has to change the layout according to the device. On landscape tablets (layout-sw600dp-land) I have a layout with two fragments and other devices will have only one fragment. This is done by two layout files in appropiate folders.

On these smaler devices, the second fragment is used as a dialog.

I'm not really sure how to implement this all. The first fragment contains a ListView with all kind of tasks. When one of those is clicked, an editing window should appear to the right fragment. On small devices, the fragment doesn't exist so it needs to be started as an Activity. Currently this editing window is a FragmentActivity.

How do I do this? I'm not sure if it's really harder, but I think the Fragment inside Fragment confuses me.

Upvotes: 0

Views: 672

Answers (2)

user
user

Reputation: 87064

I'm not really sure how to implement this all.

This shouldn't be too hard. It's conceptually as the multi pane project but instead of juggling between activities using appropriate fragments you'll work with nested fragments.

You'll have a master/wrapper fragment in the ViewPager which will represent the adaptive page which will have either one or two nested fragment depending on the current configuration(those fragments will need to be attached at runtime(a limitation of the nested fragments)). Knowing the current configuration you also need to handle the selection/click/trigger event appropriately either by starting a new activity(this is what I understood from your question, but you're a little ambiguous here) or setting up the details fragment in the same wrapper fragment.

I've made a small sample, related to your problem, that you can find here. I hope is what you want, of course keep in mind that is something basic.

Upvotes: 2

Subramanian Ramsundaram
Subramanian Ramsundaram

Reputation: 1347

First Convert That Editing Window from Activity to Fragment.

Desing the different page for tab and mobile like: 1. For Tab - Design the page like listview in left side and framelayout at right to listview 2. For device - Listview in one page and create another activity for editing window

Now you have two different page for same activity by using layout folder right.

Now you need to Check whether The framlayout is null or not. If null, then your app running in phone so you can trigger next activity which have editing window when you click the list item. If not null , then you have framelayout in right side of listview so just attach the editing fragment into framelayout.

Upvotes: 0

Related Questions