EDIT: See my answer below-->
I am wanting to have a view that when swiped to the right, the listView is shown. Very much similar to what is implemented in the new Google Play Store (Sample image below). I think its a ViewPager but I tried duplicating it without prevail. I was thinking it may just be that the 'listView Page' width attribute was set to a specific dp but that doesn't work. I also tried modifying pakerfeldt's viewFlow and cant figure out how Google does this
Am I on the right track? If someone has an idea how to duplicate this, I would greatly appreciate it. I think this may become a popular new way of showing a navigation view on tablets....? Code would be best of help. Thank you!!
Swipe right:
Finnished swipe; the layout shows the list and PART OF THE SECOND FRAGMENT (EXACTLY AS SHOWN) The list fragment does not fill the screen:
When the user swipes left, the main page is only shown and if the user swipes left again the viewPager continues to the next page.
The following code achieves the desired effect:
In PageAdapter :
#Override
public float getPageWidth(int position) {
if (position == 0) {
return(0.5f);
} else {
return (1.0f);
}
Reading your question one last time... make sure you also set up specific layouts for each size device. In your screenshots it looks like your trying to run this on a tablet. Are you getting the same results on a phone?
Setting up your Layout
Make sure your layout is simular to this and has the ViewPager:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/body_background">
<include layout="#layout/pagerbar" />
<include layout="#layout/colorstrip" />
<android.support.v4.view.ViewPager
android:id="#+id/example_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
Setting up your Activity
Setup your PagerAdapter in your "FragmentActivity" and make sure you implement "OnPageChangeListener". Then properly setup your PagerAdapter in your onCreate.
public class Activity extends FragmentActivity
implements ViewPager.OnPageChangeListener {
...
public void onCreate(Bundle savedInstanceState) {
PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
pager = (ViewPager) findViewById(R.id.example_pager);
pager.setAdapter(adapter);
pager.setOnPageChangeListener(this);
pager.setCurrentItem(MyFragment.PAGE_LEFT);
...
}
/* setup your PagerAdapter which extends FragmentPagerAdapter */
static class PagerAdapter extends FragmentPagerAdapter {
public static final int NUM_PAGES = 2;
private MyFragment[] mFragments = new MyFragment[NUM_PAGES];
public PagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
#Override
public int getCount() {
return NUM_PAGES;
}
#Override
public Fragment getItem(int position) {
if (mFragments[position] == null) {
/* this calls the newInstance from when you setup the ListFragment */
mFragments[position] = MyFragment.newInstance(position);
}
return mFragments[position];
}
}
...
Setting up your Fragment
When you setup your actual ListFragment (your listViews) you can create multiple instances with arguments like the following:
public static final int PAGE_LEFT = 0;
public static final int PAGE_RIGHT = 1;
static MyFragment newInstance(int num) {
MyFragment fragment = new MyFragment();
Bundle args = new Bundle();
args.putInt("num", num);
fragment.setArguments(args);
return fragment;
}
When you reload the listViews (how ever you decide to implement this) you can figure out which fragment instance you are on using the arguments like so:
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
If you step through your code you will notice that it will step through each instance so the above code is only needed in your onCreate and a reload method may look like this:
private void reloadFromArguments() {
/* mNum is a variable which was created for each instance in the onCreate */
switch (mNum) {
case PAGE_LEFT:
/* maybe a query here would fit your needs? */
break;
case PAGE_RIGHT:
/* maybe a query here would fit your needs? */
break;
}
}
Few Sources that may help you out with examples that you could build from rather then starting from scratch:
More explanation and example from playground.
http://blog.peterkuterna.net/2011/09/viewpager-meets-swipey-tabs.html
which is references to:
http://code.google.com/p/android-playground/
More info and some good linkage.
http://www.pushing-pixels.org/2012/03/16/responsive-mobile-design-on-android-from-view-pager-to-action-bar-tabs.html
If you have more specific questions post and I can always Edit (update) my answer to address your questions. Good Luck! :)
Sorry for the late update. I implemented this from walkingice on Gethub with very little modification. Just use a conditional statement for a GestureDetector to swipe it into view only when a ViewPager id of '0' is in view. I also added a toggle whithin my ActionBar
ViewPager is a part of the Compatibly Package
If you're using Fragments, then you can use ViewPager to swipe between them.
Here's an example of combining Fragments and ViewPager
In your particular case, you would want to create a ListFragment and then implement ViewPager.
I think you are looking to implement a "side navigation" beside a standard ViewPager.
I've read 2 different articles on this pattern:
The first one on the pattern itself:
Android Ui Pattern Emerging UI Pattern - Side Navigation
The second on a more detailed way of who to build it:
Cyril Mottier Fly-in app menu #1 #2 #3
This second article is referenced in Android Ui Pattern blog.
With a little Trick, the behavior can be achieved with the ScrollView-Behavior inside the ViewPager. If you only want to restrict the area of the most left fragment, you can restrict the scroll limits of the ScrollView.
In your case:
in the onPageChangeListener of the ViewPager do something like that:
#Override
public void onPageScrollStateChanged(int arg0) {
restrictLeftScroll();
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
restrictLeftScroll();
}
#Override
public void onPageSelected(int arg0) {
}
private void restrictLeftScroll() {
if (display != null) {
/* get display size */
Point size = new Point();
display.getSize(size);
/* get desired Width of left fragment */
int fragmentWidth = getResources().getDimensionPixelSize(R.dimen.category_fragment_width);
if (mViewPager.getScrollX() < size.x - fragmentWidth) {
mViewPager.scrollTo(size.x - fragmentWidth, mViewPager.getScrollY());
}
}
}
This piece of code worked for me without problems. ;)
Related
I have a FragmentPagerAdapter for a viewPager Which initially has only one Fragment in it. I want to dynamically add a new Fragment to the adapter when user swipes from right to left, and dynamically remove a Fragment when user swipes from left to right.I have tried to use this library https://github.com/commonsguy/cwac-pager but in that library we have an option to add and remove fragments on button clicks. I have tried to add a OnPageChangeListener to the viewpager but the callback methods ( onPageScrolled and onPageScrollStateChanged) are being called more than once which results in addition of more than one fragment to the FragmentPagerAdapter. So please shed some light on how to do this.
#dora: i think in your case FragmentStatePagerAdapter will help you. I have mentioned its use below as per my understanding.I hope it will help you in taking decision.
There are two ways to implement ViewPager:
• FragmentStatePagerAdapter
• FragmentPagerAdapter
FragmentStatePagerAdapter class consumes less memory, because it destroys fragments, as soon as they are not visible to user, keeping only saved state of that fragment
FragmentPagerAdapter: when there are less number of fragments. But using AndroidFragmentPagerAdapter for large number of fragments would result choppy and laggy UX.
Number of page hold by a viewPager?
The number of items that any ViewPager will keep hold of is set by the setOffscreenPageLimit() method. The default value for the offscreen page limit is 3. This means ViewPager will track the currently visible page, one to the left, and one to the right. The number of tracked pages is always centered around the currently visible page.
Please follow this link for code: http://www.truiton.com/2013/05/android-fragmentpageradapter-example/
I know this post is old, but I struggled to figure this out so I'll answer it anyway.
You want to use FragmentStatePagerAdapter and override getItemPosition(). Create a list of stuff you want to pass down to the fragment, call notifyDataSetChanged(), and you're all set!
Here's the adapter:
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
List<String> mKeyList = new ArrayList<>();
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return PlaceholderFragment.newInstance(mKeyList.get(position));
}
#Override
public int getCount() {
return mKeyList.size();
}
#Override
public CharSequence getPageTitle(int position) {
return "SCOUT " + (getCount() - position);
}
public void add(int position, String key) {
mKeyList.add(position, key);
notifyDataSetChanged();
}
}
And here's the fragment:
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SCOUT_KEY = "scout_key";
public static PlaceholderFragment newInstance(String key) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putString(ARG_SCOUT_KEY, key);
fragment.setArguments(args);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.current_scout_fragment, container, false);
//getArguments().getString(ARG_SCOUT_KEY));
return rootView;
}
}
I want to dynamically add a new Fragment to the adapter when user swipes from right to left, and remove dynamically remove a Fragment when user swipes from left to right.
AFAIK, that will not be supported by any PagerAdadpter. It certainly will not be supported by ArrayPagerAdapter. The page needs to exist, otherwise you cannot swipe to it. You cannot swipe first, then add the page later.
Moreover, I have never found a use case for your proposed pattern that could not be handled by having the page be in the adapter, but not populating the page (i.e., whatever the expensive work is that you appear to be trying to avoid) until the swipe begins.
I understand the lowest number I can give setOffscreenPageLimit(int) is 1. but I need to load one page at a time because memory problems.
Am i going to have to use the old style tabhost etc? or is there a way/hack I can make my viewPager load one page at a time?
My Adapter extends BaseAdapter with the ViewHolder patern.
I was having the same problem and I found the solution for it:
Steps:
1) First Download the CustomViewPager Class from this link.
2) Use that class as mentioned below:
In Java:
CustomViewPager mViewPager;
mViewPager = (CustomViewPager) findViewById(R.id.swipePager);
mViewPager.setOffscreenPageLimit(0);
In XML:
<com.yourpackagename.CustomViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipePager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Now only one page will be loaded at once.
P.S: As per the question's requirement, I have posted the solution for Viewpager. I haven't tried the same with TabLayout yet. If I will find any solution for that I will update the answer.
In this file, KeyEventCompat is used it may not found by the android studio because KeyEnentCompat class was deprecated in API level 26.0.0 so you need to replace KeyEventCompat to event for more details you can view
https://developer.android.com/sdk/support_api_diff/26.0.0-alpha1/changes/android.support.v4.view.KeyEventCompat
As far as I know, that is not possible when using the ViewPager. At least not, when you want your pages to be swipe-able.
The explaination therefore is very simple:
When you swipe between two pages, there is a Point when both pages need to be visible, since you cannot swipe between two things when one of those does not even exist at that point.
See this question for more: ViewPager.setOffscreenPageLimit(0) doesn't work as expected
CommonsWare provided a good explaination in the comments of his answer.
but I need to load one page at a time because memory problems.
That presumes that you are getting OutOfMemoryErrors.
Am i going to have to use the old style tabhost etc?
Yes, or FragmentTabHost, or action bar tabs.
or is there a way/hack I can make my viewPager load one page at a time?
No, for the simple reason that ViewPager needs more than one page at a time for the sliding animation. You can see this by using a ViewPager and swiping.
Or, you can work on fixing your perceived memory problems. Assuming this app is the same one that you reported on earlier today, you are only using 7MB of heap space. That will only result in OutOfMemoryErrors if your remaining heap is highly fragmented. There are strategies for memory management (e.g., inBitmap on BitmapOptions for creating bitmaps from external sources) that help address such fragmentation concerns.
My Adapter extends BaseAdapter with the ViewHolder patern.
BaseAdapter is for use with AdapterView, not ViewPager.
I have an Answer for this. The above said method setUserVisibleHint() is deprecated and you can use setMaxLifecycle() method. For loading only the visible fragment you have to set the behaviour to BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT in the viewpager adapter. ie; in the Constructor. And for handling the fragment use onResume() method in the fragment.
In this way you can load only one fragment at a time in the viewpager.
public static class MyAdapter extends FragmentStatePagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
}
#Override
public int getCount() {
return NUM_ITEMS;
}
#Override
public Fragment getItem(int position) {
return ArrayListFragment.newInstance(position);
}
}
In Kotlin:
class MyAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT )
Also use with FragmentPagerAdapter (now deprecated) in same way
By using this method you can load one page at time in tab layout with view pager`
#Override
public void onResume() {
super.onResume();
if (getUserVisibleHint() && !isVisible) {
Log.e("~~onResume: ", "::onLatestResume");
//your code
}
isVisible = true;
}
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser && isVisible) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//your code
}
}, 500);
}
}
`
Override the setUserVisibleHint and add postDelayed like below in your every fragments.
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
if (isVisibleToUser)
Handler().postDelayed({
if (activity != null) {
// Do you stuff here
}
}, 200)
super.setUserVisibleHint(isVisibleToUser)
}
I can manage by this way and its working fine now for me.
First, copy in the SmartFragmentStatePagerAdapter.java which provides the intelligent caching of registered fragments within our ViewPager. It does so by overriding the instantiateItem() method and caching any created fragments internally. This solves the common problem of needing to access the current item within the ViewPager.
Now, we want to extend from SmartFragmentStatePagerAdapter copied above when declaring our adapter so we can take advantage of the better memory management of the state pager:
public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
// Sparse array to keep track of registered fragments in memory
private SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
public SmartFragmentStatePagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
// Register the fragment when the item is instantiated
#Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
registeredFragments.put(position, fragment);
return fragment;
}
// Unregister when the item is inactive
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
registeredFragments.remove(position);
super.destroyItem(container, position, object);
}
// Returns the fragment for the position (if instantiated)
public Fragment getRegisteredFragment(int position) {
return registeredFragments.get(position);
}
}
// Extend from SmartFragmentStatePagerAdapter now instead for more dynamic ViewPager items
public static class MyPagerAdapter extends SmartFragmentStatePagerAdapter {
private static int NUM_ITEMS = 3;
public MyPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
// Returns total number of pages
#Override
public int getCount() {
return NUM_ITEMS;
}
// Returns the fragment to display for that page
#Override
public Fragment getItem(int position) {
switch (position) {
case 0: // Fragment # 0 - This will show FirstFragment
return FirstFragment.newInstance(0, "Page # 1");
case 1: // Fragment # 0 - This will show FirstFragment different title
return FirstFragment.newInstance(1, "Page # 2");
case 2: // Fragment # 1 - This will show SecondFragment
return SecondFragment.newInstance(2, "Page # 3");
default:
return null;
}
}
// Returns the page title for the top indicator
#Override
public CharSequence getPageTitle(int position) {
return "Page " + position;
}
}
You actually don't need a custom ViewPager.
I had the same issue and I did like this.
Keep the setOffscreenPageLimit() as 1.
Use fragment's onResume and onPause lifecycle methods.
Initialize and free-up memories on these lifecycle methods.
I know this is an old post, but I stumbled upon this issue and found a good fix if your loading fragments. Simply, check if the user is seeing the fragment or not by overriding the setUserVisibleHint(). After that load the data.
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
getData(1, getBaseUrl(), getLink());
}
}
I'm working on a specialized eBook application, where one of the requirements is that it should only display one page of text at a time, with formatting and what not. This proved more challenging than I thought it would, but I've finally managed to do it successfully.
However, now I've run into another problem, namely that the client wants to be able to flip back and forth between pages, ViewPager-style, where the page follows the finger. Now, the number of pages in these books and scriptures aren't predetermined, as I calculate them on-the-fly, each time a chapter is loaded, so that the view automatically handles changes in text size, etc.
I've been looking into various forms of "unlimited ViewPager-flipping", but thus far I haven't been able to find one that seems to work for my purpose.
What I've been considering, and that I hope someone may be able to help me with, is this:
Three pages, sort of. The one being viewed currently, and one on each side for the flipping.
When the user flips to a new page, the views will switch places behind the scenes, so that the new page becomes the one in the middle, and loads the next page, while moving the previously viewed page to the opposite end.
It doesn't technically have to be a ViewPager, if the animation, including the gesture-following, can be achieved in some other way.
I would offer up extra reputation points for this, as I'd really love to solve this quickly, but unfortunately I haven't managed to get a lot of those yet.
When you want to solve your problem with a ViewPager, you need this in your onCreate method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPager = (ViewPager) findViewById(R.id.pager);
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
// Capture ViewPager page swipes
ViewPager.SimpleOnPageChangeListener ViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
super.onPageSelected(position);
if (fistswitch) {
mPager.setCurrentItem(1);
fistswitch = false;
} else {
// here you can use the replace method, to switch the
// fragment behind the scenes
ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
Collections.addAll(fragmentList, new Fr2(), new Fr3(), new Fr4());
mPagerAdapter.addFragments(fragmentList);
// after the first switch you can use the the second page
// continuously as middle
mPager.setCurrentItem(1);
}
}
};
mPager.setOnPageChangeListener(ViewPagerListener);
mPagerAdapter = new ViewPagerAdapter(fm);
mPager.setAdapter(mPagerAdapter);
ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
Collections.addAll(fragmentList, new Fr1(), new Fr2(), new Fr3());
mPagerAdapter.addFragments(fragmentList);
}
The pager adapter class can be a private class in your activity like this:
private class ViewPagerAdapter extends FragmentStatePagerAdapter {
private List<Fragment> fragmentList = new ArrayList<Fragment>();
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
public void addFragments(List<Fragment> fragments) {
fragmentList.clear();
fragmentList.addAll(fragments);
notifyDataSetChanged();
}
public void replaceFragment(int position, Fragment fr) {
fragmentList.remove(position);
fragmentList.add(position, fr);
notifyDataSetChanged();
}
#Override
public int getItemPosition(Object object) {
if (fragmentList.contains(object)) {
return POSITION_UNCHANGED;
}
return POSITION_NONE;
}
#Override
public Fragment getItem(int item) {
if (item >= fragmentList.size()) {
return null;
}
return fragmentList.get(item);
}
#Override
public int getCount() {
return fragmentList.size();
}
}
I have not tested the code, but it works for me in a similar case.
There are some good ways to add animation to a ViewPager and alternatively use your own custom views. The first is an open source project called JazzyViewPager by jfeinstein10
This library is really nice and have some animations built in. I've looked at the source in the past and it should be simple to create your own animations if necessary.
The second option is using what's used in JazzyViewPager, namely ViewHelper, which is a class is in the NineOldAndroids animation library by Jake Wharton.
I'm following the BitMapFun tutorial from the android developer docs. As I'm a total newby to Android/Java programming in general.
I have created a custom ImageViewer (called TouchImageView) which allows the user to zoom, doubletap, etc... and applied it on the ImageDetailFragment class.
In the TouchImageView class I have a boolean variable that can detect if the User zoomed in or not, and in the case it's zoomedIn it will also flag if the image is at the border side. (Thus the zoomedIn bit and the border of the screen matters)
I want apply this logic to enable or disable the ViewPager to allow the user to scroll to the next/previous page (read Fragment) This ViewPager is located in the ImageDetailActivity that implements the FragmentActivity
As my code is now, if I move left or right (in the zoomed in state) instead of moving the image, it will go to the next Fragment instead of scrolling left or right. Unless I firstly move up or down, where I can then scroll the image.
So I thought, if I have a boolean in the Fragment that I can check to in order for my Activiy to enable/disable the ViewPager then I can 'control' the way the scroll works.
Is this logic correct? and if so, how can I retrieve the boolean from the Fragment in my DetailActivity class. I have tried doing it with an Interface, however I'm getting always a false reply back (due to the initalization of fragments during the onCreate?) So I need something that can retrieve that boolean during run-time on the displayed fragment. However from my code below it's never working.
public void onCreate(Bundle savedInstanceState) {
.... Do stuff like fetching images and caching etc ....
mPager = (ScrollViewPager) findViewById(R.id.pager);
mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), imgs.getImagesLocal().length);
mPager.setAdapter(mAdapter);
mPager.setPageMargin((int) getResources().getDimension(R.dimen.image_detail_pager_margin));
mPager.setOffscreenPageLimit(2);
mPager.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
//v.mAdapter.mCurItem
ScrollViewPager scroll = (ScrollViewPager) v;
//Log.d(TAG, "-----------------Current pos is "+ scroll.getCurrentItem());
ImageDetailFragment frag = (ImageDetailFragment) mAdapter.getItem(scroll.getCurrentItem());
if(frag.isPageChangeable())
{
Log.d(TAG, "-----------------Page is zoomed");
}else
{
Log.d(TAG, "----------------------Page is not Zoomed");
}
return false;
}
});
}
The Fragment initialization that I got is.
/**
* The main adapter that backs the ViewPager. A subclass of FragmentStatePagerAdapter as there could be a large number of items in the ViewPager and we don't want to retain
* them all in memory at once but create/destroy them on the fly.
*/
private class ImagePagerAdapter extends FragmentStatePagerAdapter {
private final int mSize;
public ImagePagerAdapter(FragmentManager fm, int size) {
super(fm);
mSize = size;
}
#Override
public int getCount() {
return mSize;
}
#Override
public Fragment getItem(int position) {
return ImageDetailFragment.newInstance(imgs.getImagesLocal()[position], position, imgs.getImagesLocal().length);
}
}
If you want to take a look at the full code you can download it here.
For the prevention of the swipe/fling I thought of using the following information found on this stackoverflow post
I found a partial solution, whiiii!
I implemented the Disable ViewPager as mentioned in the link.
Then added the following in the onClick method.
public void onClick(View v) {
TouchImageViewLocal ti = (TouchImageViewLocal) findViewById(R.id.imageView);
if(ti.isZoomed()){
Log.d(TAG, "-----------------------------------------is zoomed in? " + ti.isZoomed());
mPager.setPagingEnabled(false);
}else
{
Log.d(TAG, "-----------------------------------------is zoomed in? " + ti.isZoomed());
mPager.setPagingEnabled(true);
}
This allows the screen if it's zoomed in to stop/start the swipe, however, I still have to find the on edge detection. :-)
I've been working on an app to display media that has a layout that resembles the below mockup. Each fragment is a pair of linearlayout elements with 4 custom layouts to show a imageview and textview.
If I have more than 2 fragments and flick right-left to navigate through the various fragments the 4 custom imageviews are not being displayed inside the fragment. I assume it's due to garbage collection resulting from Android loading all images onto the heap.
I've tried using the onResume() methods of each fragment to rebuild the layouts when they are visible, with disastrous results.
Since different users may have different fragment counts based on how they set up their media, what would be considered best practice for an activity that's image heavy like this. Also does anyone have any suggestions for how to tell if the fragment's layout needs to be rebuilt.
This is my first Android app, the learning curve feels quite steep.
EDIT: As requested, here is the adapter and the fragment.
public static class HomeScreenPagerAdapter extends FragmentPagerAdapter {
public HomeScreenPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
MediaPayload mediaWrapper = new MediaPayload();
mediaWrapper.Item = items[i];
Fragment fragment = new EhsFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("InterActivityPayload", payload);
bundle.putSerializable("MediaWrapper", mediaWrapper);
fragment.setArguments(bundle);
return fragment;
}
#Override
public int getCount() {
return items.length;
}
#Override
public CharSequence getPageTitle(int position) {
return items[position].Name;
}
}
The fragment is 500+ lines, so I dropboxed it. I can post it inline if people prefer, but it's a lot of code.