As shown, in conjunction with the ViewPager and Fragment found ViewPager after exiting, fragment did not quit,
When I switch on the left leads to the menu inside, get back into the "local", Fragment not refreshed, it shows nothing.
By LOG printing, found after creating fragment, no further change over the life cycle. But there is DetachedFromWindow
ViewPager
Use circulated on the Internet is the most basic FragmentPagerAdapter and ViewPager.
Great God seeking advice!
Reply:
http://download.csdn.net/detail/lqgyt1/6633105
The Demo wrote a little feedback to my question, for Fragment and ViewPager interested, we can discuss together.
Reply:
This year we should rely on themselves. . Achieve their own FragmentAdapater, speed accounted floor, to the sub myself.
/ *
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* Distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* Limitations under the License.
* /
package com.tubban.viewpager;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
/ **
* Implementation of {@ link android.support.v4.view.PagerAdapter} that
* Represents each page as a {@ link Fragment} that is persistently
* Kept in the fragment manager as long as the user can return to the page.
*
*This version of the pager is best for use when there are a handful of
* Typically more static fragments to be paged through, such as a set of tabs.
* The fragment of each page the user visits will be kept in memory, though its
* View hierarchy may be destroyed when not visible. This can result in using
* A significant amount of memory since fragment instances can hold on to an
* Arbitrary amount of state. For larger sets of pages, consider
* {@ Link FragmentStatePagerAdapter}.
*
*When using FragmentPagerAdapter the host ViewPager must have a
* Valid ID set.
*
*Subclasses only need to implement {@ link # getItem (int)}
* And {@ link # getCount ()} to have a working adapter.
*
*Here is an example implementation of a pager containing fragments of
* Lists:
*
* {@ Sample development/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java
* Complete}
*
*The
R.layout.fragment_pagerresource of the top-level fragment is:
*
* {@ Sample development/samples/Support4Demos/res/layout/fragment_pager.xml
* Complete}
*
*The
R.layout.fragment_pager_listresource containing each
* Individual fragment's layout is:
*
* {@ Sample development/samples/Support4Demos/res/layout/fragment_pager_list.xml
* Complete}
* /
public abstract class MyFragmentViewAdapater extends PagerAdapter {
private static final String TAG = "FragmentPagerAdapter";
private static final boolean DEBUG = true;
private final FragmentManager mFragmentManager;
public MyFragmentViewAdapater (FragmentManager fm) {
mFragmentManager = fm;
}
/ **
* Return the Fragment associated with a specified position.
* /
public abstract Fragment getItem (int position);
@ Override
public void startUpdate (ViewGroup container) {
}
@ Override
public Object instantiateItem (ViewGroup container, int position) {
Fragment fragment = getItem (position);
if (! fragment.isAdded ()) {
FragmentTransaction ft = mFragmentManager.beginTransaction ();
ft.add (fragment, fragment.getClass () getName ().);
ft.commit ();
mFragmentManager.executePendingTransactions ();
}
if (fragment.getView (). getParent () == null) {
container.addView (fragment.getView ()); / / increases as the layout
viewpager}
return fragment.getView ();
}
@ Override
public void destroyItem (ViewGroup container, int position, Object object) {
container.removeView ((View) object);
}
@ Override
public boolean isViewFromObject (View view, Object object) {
return view == object;
}
@ Override
public Parcelable saveState () {
return null;
}
@ Override
public void restoreState (Parcelable state, ClassLoader loader) {
}
private static String makeFragmentName (int viewId, int index) {
return "android: switcher:" + viewId + ":" + index;
}
}
Reply:
mark about learning about. . .
No comments:
Post a Comment