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:edu.stanford.mobisocial.dungbeetle.feed.objects.PhoneStateObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//from w  w w. j  a v a2  s .  co m
    TextView valueTV = new TextView(context);
    valueTV.setText(asText(content));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);
}

From source file:com.johnny.gank.ui.adapter.PicturePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(container.getContext()).inflate(R.layout.pager_item_picture, container,
            false);/*from  w  w w  .j a  v  a  2 s .co m*/
    ViewHolder holder = new ViewHolder(view);
    GankNormalItem item = mItems.get(position);
    Glide.with(container.getContext()).load(item.url).dontAnimate().centerCrop().into(holder.vPic);
    container.addView(view);
    return view;
}

From source file:android.support.v17.leanback.app.BrandedSupportFragment.java

/**
 * Inflate title view and add to parent.  This method should be called in
 * {@link Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)}.
 * @param inflater The LayoutInflater object that can be used to inflate
 * any views in the fragment,/*from w w w  . j a va 2 s.  c  om*/
 * @param parent Parent of title view.
 * @param savedInstanceState If non-null, this fragment is being re-constructed
 * from a previous saved state as given here.
 */
public void installTitleView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View titleLayoutRoot = onInflateTitleView(inflater, parent, savedInstanceState);
    if (titleLayoutRoot != null) {
        parent.addView(titleLayoutRoot);
        setTitleView(titleLayoutRoot.findViewById(R.id.browse_title_group));
    } else {
        setTitleView(null);
    }
}

From source file:cc.metapro.openct.customviews.TableChooseDialog.java

private void setView() {
    mTableIds = new ArrayList<>(tableMap.size());
    for (String s : tableMap.keySet()) {
        mTableIds.add(s);/* www  . ja v a  2s.c  o m*/
    }

    final List<View> views = new ArrayList<>(mTableIds.size());
    for (String s : mTableIds) {
        TextView textView = new TextView(getActivity());

        String content = tableMap.get(s).toString();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            textView.setText(Html.fromHtml(content, Html.FROM_HTML_MODE_COMPACT));
        } else {
            textView.setText(Html.fromHtml(content));
        }
        views.add(textView);
    }

    mTabBar.setupWithViewPager(mViewPager);
    mViewPager.setAdapter(new PagerAdapter() {
        @Override
        public int getCount() {
            return mTableIds.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTableIds.get(position);
        }

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

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

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

From source file:com.android.settings.PreviewSeekBarPreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View root = super.onCreateView(inflater, container, savedInstanceState);
    final ViewGroup listContainer = (ViewGroup) root.findViewById(android.R.id.list_container);
    listContainer.removeAllViews();//from  ww  w  .  j  av  a2 s  . com

    final View content = inflater.inflate(mActivityLayoutResId, listContainer, false);
    listContainer.addView(content);

    mLabel = (TextView) content.findViewById(R.id.current_label);

    // The maximum SeekBar value always needs to be non-zero. If there's
    // only one available value, we'll handle this by disabling the
    // seek bar.
    final int max = Math.max(1, mEntries.length - 1);

    final LabeledSeekBar seekBar = (LabeledSeekBar) content.findViewById(R.id.seek_bar);
    seekBar.setLabels(mEntries);
    seekBar.setMax(max);
    seekBar.setProgress(mInitialIndex);
    seekBar.setOnSeekBarChangeListener(new onPreviewSeekBarChangeListener());

    mSmaller = content.findViewById(R.id.smaller);
    mSmaller.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int progress = seekBar.getProgress();
            if (progress > 0) {
                seekBar.setProgress(progress - 1, true);
            }
        }
    });

    mLarger = content.findViewById(R.id.larger);
    mLarger.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int progress = seekBar.getProgress();
            if (progress < seekBar.getMax()) {
                seekBar.setProgress(progress + 1, true);
            }
        }
    });

    if (mEntries.length == 1) {
        // The larger and smaller buttons will be disabled when we call
        // setPreviewLayer() later in this method.
        seekBar.setEnabled(false);
    }

    final Context context = getContext();
    final Configuration origConfig = context.getResources().getConfiguration();
    final boolean isLayoutRtl = origConfig.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
    Configuration[] configurations = new Configuration[mEntries.length];
    for (int i = 0; i < mEntries.length; ++i) {
        configurations[i] = createConfig(origConfig, i);
    }

    mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager);
    mPreviewPagerAdapter = new PreviewPagerAdapter(context, isLayoutRtl, mPreviewSampleResIds, configurations);
    mPreviewPager.setAdapter(mPreviewPagerAdapter);
    mPreviewPager.setCurrentItem(isLayoutRtl ? mPreviewSampleResIds.length - 1 : 0);
    mPreviewPager.addOnPageChangeListener(mPreviewPageChangeListener);

    mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
    if (mPreviewSampleResIds.length > 1) {
        mPageIndicator.setViewPager(mPreviewPager);
        mPageIndicator.setVisibility(View.VISIBLE);
        mPageIndicator.setOnPageChangeListener(mPageIndicatorPageChangeListener);
    } else {
        mPageIndicator.setVisibility(View.GONE);
    }

    setPreviewLayer(mInitialIndex, false);
    return root;
}

From source file:at.alladin.rmbt.android.adapter.result.QoSCategoryPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Context context = container.getContext();

    //QoSTestResultEnum key = QoSTestResultEnum.values()[position];
    QoSTestResultEnum key = titleList.get(position);
    View view = null;/*from   w ww . j a  v  a2s .  c o m*/
    view = new QoSCategoryView(context, activity, results.getTestDescMap().get(key), resultMap.get(key),
            descMap.get(key));
    container.addView(view);
    return view;
}

From source file:cs.umass.edu.prepare.view.custom.CalendarAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;//from  ww w.  j av  a  2s.com
    TextView dayView;
    if (convertView == null) { // if it's not recycled, initialize some attributes
        v = View.inflate(context, R.layout.calendar_item, null);
    }

    ViewGroup insertPoint = (ViewGroup) v.findViewById(R.id.layout_calendar_item);
    insertPoint.removeAllViews();

    dayView = (TextView) View.inflate(context, R.layout.textview_date, null);
    insertPoint.addView(dayView);

    // disable empty days from the beginning
    if (dateStrings[position].equals("")) {
        dayView.setClickable(false);
        dayView.setFocusable(false);
    } else {
        v.setBackgroundResource(R.drawable.list_item_background);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, month.get(Calendar.YEAR));
        cal.set(Calendar.MONTH, month.get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStrings[position]));
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (month.get(Calendar.YEAR) == selectedDate.get(Calendar.YEAR)
                && month.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH)
                && dateStrings[position].equals("" + selectedDate.get(Calendar.DAY_OF_MONTH))) {
            int selectedColor = ContextCompat.getColor(context,
                    R.color.color_calendar_item_background_selected);
            v.setBackgroundColor(selectedColor);
        } else if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
            dayView.setTextColor(Color.GRAY);
        }
    }
    dayView.setText(dateStrings[position]);

    // create date string for comparison
    String dateStr = dateStrings[position];

    if (displayType == DisplayType.BASIC) {
        v.setMinimumHeight(0);
        return v; // do not populate cells
    }
    v.setMinimumHeight(325); // TODO: not device independent

    if (medications == null || adherenceData == null) {
        Log.w(TAG, "Warning : No adherenceData found.");
        return v; // do not populate cells
    }

    if (dateStr.equals(""))
        return v;

    Calendar dateKey = Utils.getDateKey(month.get(Calendar.YEAR), month.get(Calendar.MONTH),
            Integer.parseInt(dateStr));
    if (adherenceData.containsKey(dateKey)) {
        populateCell(dateKey, insertPoint);
    }

    return v;
}

From source file:com.hippo.widget.viewpager.RecyclerPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    E holder = mRecycler.obtain();/*from  ww w  .  jav a 2  s .  c  o m*/
    if (holder == null) {
        holder = createPagerHolder(container);
    }

    holder.oldPosition = INVALID_POSITION;
    holder.position = position;

    bindPagerHolder(holder, position);
    container.addView(holder.itemView);

    mAttachedHolder.add(holder);

    return holder;
}

From source file:ch.gianulli.flashcards.lists.CardsAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    Flashcard result = Flashcard.inflateView(mInflater, container, this);
    result.setFontSize(mFontSize);/*ww  w .  j  av  a  2 s .c  o m*/
    result.setMathMLEnabled(mMathMLEnabled);
    result.setCard(mCards.get(position));

    if (mAnsweredCards.indexOfKey(position) >= 0) {
        result.deactivateCard(mAnsweredCards.get(position));
    }

    container.addView(result.getView());
    return result;
}

From source file:ch.epfl.sweng.evento.gui.infinite_pager_adapter.InfinitePagerAdapter.java

/**
 * This method is only called, when this pagerAdapter is initialized.
 *///from  w  w  w  .  ja  v a2  s .  c om
@Override
public final Object instantiateItem(final ViewGroup container, final int position) {
    if (Constants.DEBUG) {
        Log.i("InfiniteViewPager", String.format("instantiating position %s", position));
    }
    final PageModel<T> model = createPageModel(position);
    mPageModels[position] = model;
    container.addView(model.getParentView());
    return model;
}