Fragment instantiate - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Fragment instantiate method.

This code example shows how to use the following methods:getAdapter, getCurrentItem, setCurrentItem
 
    /** 
     * Hack to enable reloading fragments while they are being viewed 
     */ 
    public void forceReload() { 
        int position = getCurrentItem();
        setAdapter(getAdapter()); 
        setCurrentItem(position, false);
    } 
 
    /** 
     * Show the supplied filter, adding it to the data source if it doesn't exist 
     * @param f 
     */ 
    public void showFilter(Filter f) { 
        TaskListFragmentPagerAdapter adapter = (TaskListFragmentPagerAdapter) getAdapter();
        showFilter(adapter.addOrLookup(f));
    } 
 
    /** 
8
CodeRank
This code example shows how to use the following methods:
import android.view.MotionEvent; 
 
public class NestableViewPager extends ViewPager { 
 
    public NestableViewPager(Context context, AttributeSet attrs) { 
        super(context, attrs); 
    } 
 
    /** 
     * Prevent horizontal scrolling 
     */ 
     @Override 
    public boolean onInterceptTouchEvent(MotionEvent event) { 
         return false; 
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:getAdapter, getCurrentItem, onTouchEvent, getParent
    public boolean onTouchEvent(MotionEvent event) {
        final int action = event.getAction();
        if (action == MotionEvent.ACTION_DOWN) {
            //mCurrX = event.getX(); 
        } else if (action == MotionEvent.ACTION_MOVE) {
            if (getCurrentItem() == 0 && ((event.getX() - mCurrX) > mTouchSlop)) {
                // User moved finger to the right and is on the leftmost ViewGroup 
                getParent().requestDisallowInterceptTouchEvent(false); 
            } else if (getCurrentItem() == (getAdapter().getCount() - 1) && ((mCurrX - event.getX()) > mTouchSlop)) {
                // User moved finger to the left and is on the rightmost ViewGroup 
                getParent().requestDisallowInterceptTouchEvent(false); 
            } else if (Math.abs(event.getY() - mCurrY) > Math.abs(event.getX() - mCurrX)) {
                // User scrolled vertically 
                getParent().requestDisallowInterceptTouchEvent(false); 
            } 
        } 
        return super.onTouchEvent(event);
    } 
} 

7
CodeRank
This code example shows how to use the following methods:getChildAt, getMeasuredWidth, onMeasure, setMeasuredDimension
      super(context, attrs);
   } 
 
   @Override 
   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
 
      // find the first child view 
      View view = getChildAt(0);
      if (view != null) {
         // measure the first child view with the specified measure spec 
         view.measure(widthMeasureSpec, heightMeasureSpec);
      } 
 
      setMeasuredDimension(getMeasuredWidth(), measureHeight(heightMeasureSpec, view));
   } 
 
   /** 
    * Determines the height of this view 
    *  
7
CodeRank
This code example shows how to use the following methods:
 * @author Chris Banes 
 */ 
public class HackyViewPager extends ViewPager { 
 
    public HackyViewPager(Context context) {
        super(context);
    } 
 
    public HackyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    } 
 
    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try { 
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return false; 
        } 
7
CodeRank
This code example shows how to use the following methods:getCurrentItem, onInterceptTouchEvent
	@Override 
	public boolean onInterceptTouchEvent(MotionEvent event) { 
		// If a touch event is intercepted on page 1, don't do anything. 
		// This will enable scoll on blank areas, cover art, but not on buttons/seekbars 
		// If we're on page 1, all that's displayed is a list that plays nicely with ViewPager 
		if (getCurrentItem() == 0) 
			return false; 
		return super.onInterceptTouchEvent(event); 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:addView, setImageResource
		 *         need to be a View, but can be some other container of the 
		 *         page. 
		 */ 
		@Override 
		public Object instantiateItem(View collection, int position) {
			ImageView view = new ImageView(ViewPagerActivity.this);
			view.setImageResource(pics[position]);
 
			((ViewPager) collection).addView(view, 0);
 
			return view;
		} 
 
		/** 
		 * Remove a page for the given position. The adapter is responsible for 
		 * removing the view from its container, although it only must ensure 
		 * this is done by the time it returns from {@link #finishUpdate()}. 
		 *  
		 * @param container 
		 *            The containing View from which the page will be removed. 
7
CodeRank
This code example shows how to use the following methods:getAdapter, setAdapter, setCurrentItem
	super(context, attrs);
    } 
 
    @Override 
    public void setAdapter(PagerAdapter adapter) {
	super.setAdapter(adapter);
	// offset first element so that we can scroll to the left 
	setCurrentItem(0); 
    } 
 
    @Override 
    public void setCurrentItem(int item) {
	// offset the current item to ensure there is space to scroll 
	item = getOffsetAmount() + (item % getAdapter().getCount());
	super.setCurrentItem(item);
 
    } 
 
    private int getOffsetAmount() { 
	if (getAdapter() instanceof InfinitePagerAdapter) { 

6
CodeRank
This code example shows how to use the following methods:onTouchEvent
 
    @Override 
    public boolean onTouchEvent(MotionEvent ev) {
        if (this.gestureDetector != null)
            this.gestureDetector.onTouchEvent(ev);
        return super.onTouchEvent(ev);
    } 
 
    @Override 
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (this.gestureDetector != null && ev.getActionMasked() == MotionEvent.ACTION_DOWN)
            this.gestureDetector.onTouchEvent(ev);
        return super.dispatchTouchEvent(ev);
 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
import android.view.SurfaceView; 
import android.view.View; 
 
public class MapAwarePager extends ViewPager { 
  public MapAwarePager(Context context, AttributeSet attrs) { 
    super(context, attrs); 
  } 
 
  @Override 
  protected boolean canScroll(View v, boolean checkV, int dx, int x, 
                              int y) { 
    if (v instanceof SurfaceView || v instanceof PagerTabStrip) { 
      return(true); 
    } 
     
    return(super.canScroll(v, checkV, dx, x, y)); 
  } 
} 
7
CodeRank

Related Fragment instantiate Questions & Answers:

instantiate Method Overview
Like instantiate(Context, String, Bundle) but with a null argument Bundle.
See Code Examples for other Android Fragment Methods: