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.draekko.traypreferencesapp.SampleAppPreferences.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    LinearLayout content = (LinearLayout) root.getChildAt(0);
    LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar, null);

    root.removeAllViews();/* ww  w. ja  va2  s  .  c  om*/
    toolbarContainer.addView(content);
    root.addView(toolbarContainer);

    mToolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar);
    mToolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.white));
    mToolbar.setSubtitleTextColor(ContextCompat.getColor(this, R.color.white));
    mToolbar.setNavigationIcon(R.drawable.ic_back_material_light);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:com.csipsimple.wizards.impl.Ippi.java

private void updateAccountInfos(final SipProfile acc) {
    if (acc != null && acc.id != SipProfile.INVALID_ID) {
        customWizard.setVisibility(View.GONE);
        accountBalanceHelper.launchRequest(acc);
    } else {//from w w  w. java  2s .co  m
        if (firstView == null) {
            firstView = new AccountCreationFirstView(parent);
            ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent();
            firstView.setOnAccountCreationFirstViewListener(this);
            globalContainer.addView(firstView);
        }
        setFirstViewVisibility(true);
    }
}

From source file:com.andremion.heroes.ui.section.view.SectionPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    PageItemSectionBinding binding = DataBindingUtil.inflate(mInflater, R.layout.page_item_section, container,
            false);/*w w w. j  a va  2s  .  co  m*/
    SectionVO data = mItems.get(position);
    onViewBound(binding, position, data);
    container.addView(binding.getRoot());
    return binding;
}

From source file:com.joanzapata.android.BasePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = createConvertView(position, get(position), container);
    put(position, view);/* www  . java2  s .c  om*/
    container.addView(view);
    return view;
}

From source file:com.csipsimple.wizards.impl.Zadarma.java

private void updateAccountInfos(final SipProfile acc) {
    if (acc != null && acc.id != SipProfile.INVALID_ID) {
        setFirstViewVisibility(false);/*from  ww w.ja va 2  s  . co  m*/
        customWizard.setVisibility(View.GONE);
        accountBalanceHelper.launchRequest(acc);
    } else {
        if (firstView == null) {
            firstView = new AccountCreationFirstView(parent);
            ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent();
            firstView.setOnAccountCreationFirstViewListener(this);
            globalContainer.addView(firstView);
        }
        setFirstViewVisibility(true);
    }
}

From source file:com.ameron32.apps.tapnotes._trial._demo.fragment.FlippableStackViewTestFragment.java

private void initAdapter() {
    mAdapter = new PagerAdapter() {
        @Override//from w ww  .  j  a v  a  2 s .co  m
        public int getCount() {
            return colors.length;
        }

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

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            //  Object o = super.instantiateItem(container, position);

            final FrameLayout l = new FrameLayout(container.getContext());
            l.setBackgroundColor(getColorFrom(position));
            container.addView(l);

            return l;
        }

        private int getColorFrom(int position) {
            return colors[(getCount() - 1) - position];
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    };
}

From source file:com.android.messaging.ui.FixedViewPagerAdapter.java

@Override
public Object instantiateItem(final ViewGroup container, final int position) {
    final PagerViewHolder viewHolder = getViewHolder(position);
    final View view = viewHolder.getView(container);
    if (view == null) {
        return null;
    }//from   w  w  w .ja v a 2 s  . c  o m
    view.setTag(viewHolder);
    container.addView(view);
    return viewHolder;
}

From source file:com.LogIn.AdvancedPagerAdapter.java

/**
 * Instantiate the {@link View} which should be displayed at {@code position}. Here we
 * inflate a layout from the apps resources and then change the text view to signify the position.
 *//*ww  w.jav  a2  s  .  c  o m*/
@Override
public Object instantiateItem(final ViewGroup container, int position) {
    final View view;
    LayoutInflater inflater = LayoutInflater.from(container.getContext());

    if (Utility.LogInType.equals("Sleepiness")) {
        view = inflater.inflate(R.layout.visualization_scroll_sleepiness, container, false);
        container.addView(view);
        CalendarViewSleepiness cal = (CalendarViewSleepiness) view.findViewById(R.id.CalendarViewSleepiness);
        cal.setPageIndex(position);
    } else if (Utility.LogInType.equals("Depression")) {
        view = inflater.inflate(R.layout.visualization_scroll_depression, container, false);
        container.addView(view);
        CalendarViewDepression cal = (CalendarViewDepression) view.findViewById(R.id.CalendarViewDepression);
        cal.setPageIndex(position);
    } else {
        view = inflater.inflate(R.layout.visualization_scroll_mood, container, false);
        container.addView(view);
        CalendarViewMood cal = (CalendarViewMood) view.findViewById(R.id.CalendarViewMood);
        cal.setPageIndex(position);
    }
    return view;
}

From source file:com.guanyin.userface.ViewPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    if (app == null) {
        app = MyApplication.getInstance();
    }// w w  w  . jav  a 2 s .co  m
    setContentView(R.layout.activity_main_inter_face);

    initViews();

    initDatas();

    PagerAdapter pagerAdapter = new PagerAdapter() {

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(fragments.get(position));
            return fragments.get(position);
        }
    };

    viewPager.setAdapter(pagerAdapter);

}

From source file:com.momock.outlet.tab.PagerTabOutlet.java

public void attach(TabHolder target) {
    Logger.check(target != null, "Parameter target cannot be null!");
    Logger.check(target.getTabContent() instanceof ViewPager,
            "The PagerTabOutlet must contains a ViewPager content!");
    this.target = target;
    final TabHost tabHost = target.getTabHost();
    final ViewPager tabContent = (ViewPager) target.getTabContent();
    plugs = getPlugs();//  www. j a  va  2 s.co  m

    ViewPager pager = (ViewPager) target.getTabContent();
    for (int i = 0; i < plugs.getItemCount(); i++) {
        ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "The plug of PagerTabOutlet must include a ViewHolder!");
        ((ViewHolder) plug.getContent()).reset();
    }
    pager.setAdapter(new PagerAdapter() {

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

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

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

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });

    tabContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TabWidget widget = tabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            tabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    tabHost.setup();
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            int index = tabHost.getCurrentTab();
            ITabPlug plug = (ITabPlug) plugs.getItem(index);
            setActivePlug(plug);
            tabContent.setCurrentItem(index, true);
        }
    });
    for (int i = 0; i < plugs.getItemCount(); i++) {
        final ITabPlug plug = (ITabPlug) plugs.getItem(i);
        Logger.check(plug.getContent() instanceof ViewHolder,
                "Plug in PagerTabOutlet must contains a ViewHolder content!");

        TabHost.TabSpec spec = tabHost.newTabSpec("" + i);
        target.setTabIndicator(spec, plug);
        spec.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                View v = new View(tabHost.getContext());
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }

        });
        tabHost.addTab(spec);
        if (getActivePlug() == plug)
            tabHost.setCurrentTab(i);
    }
}