Example usage for android.view ViewGroup addView

List of usage examples for android.view ViewGroup addView

Introduction

In this page you can find the example usage for android.view ViewGroup addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.yanzhenjie.nohttp.sample.adapter.MainBannerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = new ImageView(container.getContext());
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageResource(IMAGES[position % IMAGES.length]);
    container.addView(imageView);
    return imageView;
}

From source file:com.csumax.maxgithubclient.fragment.ProgressFragment.java

public void setContentView(View view) {
    ensureContent();//from  w w  w  .ja  va2  s. co m
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        if (mContentView == null) {
            contentContainer.addView(view);
        } else {
            int index = contentContainer.indexOfChild(mContentView);
            // replace content view
            contentContainer.removeView(mContentView);
            contentContainer.addView(view, index);
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}

From source file:com.momock.outlet.card.PagerCardOutlet.java

public void attach(ViewPager target) {
    refTarget = new WeakReference<ViewPager>(target);
    ViewPager pager = target;/*from w  w w.  ja v a2 s.c o  m*/
    pager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return getPlugs().getItemCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ICardPlug plug = (ICardPlug) getPlugs().getItem(position);
            View view = ((ViewHolder) plug.getComponent()).getView();
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
    IDataList<IPlug> plugs = getPlugs();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ICardPlug plug = (ICardPlug) plugs.getItem(i);
        Logger.check(plug.getComponent() instanceof ViewHolder,
                "The plug of PagerCardOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getComponent()).reset();
        if (plug == this.getActivePlug()) {
            onActivate(plug);
        }
    }
}

From source file:at.jclehner.rxdroid.InfiniteViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    if (mFactory == null)
        throw new IllegalStateException("No ViewFactory supplied");

    View v = mFactory.makeView(position - CENTER);
    Util.detachFromParent(v);//from   w  w w. jav  a2  s  .c  o m
    container.addView(v);
    return v;
}

From source file:com.maxleap.mall.adapters.ProductGalleryAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    String imgUrl = mPics.get(position);
    Picasso.with(mContext).load(imgUrl).into(imageView);
    container.addView(imageView);
    return imageView;
}

From source file:com.gitstudy.rili.liarbry.YearViewSelectLayout.java

void setup(CalendarViewDelegate delegate) {
    this.mDelegate = delegate;
    this.mYearCount = mDelegate.getMaxYear() - mDelegate.getMinYear() + 1;
    setAdapter(new PagerAdapter() {
        @Override/*from  www .ja  v  a  2  s. c o  m*/
        public int getCount() {
            return mYearCount;
        }

        @Override
        public int getItemPosition(Object object) {
            return isUpdateYearView ? POSITION_NONE : super.getItemPosition(object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            YearRecyclerView view = new YearRecyclerView(getContext());
            container.addView(view);
            view.setup(mDelegate);
            view.setOnMonthSelectedListener(mListener);
            view.init(position + mDelegate.getMinYear());
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            if (object instanceof YearRecyclerView)
                container.removeView((YearRecyclerView) object);
        }
    });
    setCurrentItem(mDelegate.getCurrentDay().getYear() - mDelegate.getMinYear());
}

From source file:com.robotsandpencils.walkthrough.presentation.main.paging.screens.ScreensAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ViewGroup viewGroup = mLayouts.get(position).getView();
    ViewGroup parent = (ViewGroup) viewGroup.getParent();
    if (parent != null) {
        parent.removeView(viewGroup);//ww w .  j av a  2s .  co m
    }
    container.addView(viewGroup);
    return viewGroup;
}

From source file:com.zhihu.android.app.mirror.widget.adapter.ArtboardPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ArtboardLayout layout = (ArtboardLayout) LayoutInflater.from(container.getContext())
            .inflate(R.layout.pager_item_artboard, container, false);
    container.addView(layout);

    Artboard artboard = mList.get(position);
    layout.setTag(R.id.artboard_position, position);
    layout.setTag(R.id.artboard_id, artboard.getId());
    layout.setArtboard(artboard);/*from  w w w  .j  a v a  2  s  .  c  o m*/

    return layout;
}

From source file:de.aw.monma.charts.ChartTemplate.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ViewGroup mContainer = view.findViewById(R.id.chartDetails);
    mChart = getChart();// w ww  .j  av a 2 s. c o m
    setAttributes();
    mContainer.addView(mChart);
}

From source file:com.fuzz.emptyhusk.prefab.InlineAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    int resId = (position % 3 == 0) ? R.drawable.rectangle_wide_secondary : R.drawable.rectangle_wide_tertiary;

    ImageView inflated = new ImageView(container.getContext());
    inflated.setImageResource(resId);/*w  w w.ja va 2s. c  o m*/
    container.addView(inflated);

    viewCache.put(position, inflated);

    return inflated;
}