List of usage examples for android.view ViewGroup addView
public void addView(View child)
Adds a child view.
From source file:android.support.v14.preference.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment, TypedArrayUtils.getAttr(mStyledContext, android.support.v7.preference.R.attr.preferenceFragmentStyle, AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE), 0);/*w ww .j av a 2 s . co m*/ mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider); final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1); a.recycle(); // Need to theme the inflater to pick up the preferenceFragmentListStyle final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme); final LayoutInflater themedInflater = inflater.cloneInContext(themedContext); final View view = themedInflater.inflate(mLayoutResId, container, false); final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException("Content has view with id attribute " + "'android.R.id.list_container' that is not a ViewGroup class"); } final ViewGroup listContainer = (ViewGroup) rawListContainer; final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState); if (listView == null) { throw new RuntimeException("Could not create RecyclerView"); } mList = listView; listView.addItemDecoration(mDividerDecoration); setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } listContainer.addView(mList); mHandler.post(mRequestFocus); return view; }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * ?// w w w.ja v a 2 s . c o m * * @param container webView */ public void openLineMode(ViewGroup container) { this.myLayout = (MyAbsoluteLayout) LayoutInflater.from(mContext).inflate(R.layout.line, null); LayoutParams mLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 0, 0); myLayout.setLayoutParams(mLayoutParams); container.addView(myLayout); lineView = (LineView) myLayout.findViewById(R.id.lineView); isLineMode = true; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java
@Override public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) { PackageManager pm = context.getPackageManager(); Drawable icon = null;/*from w ww. ja va 2 s . c o m*/ String appName; if (obj.getJson() != null && obj.getJson().has(ANDROID_PACKAGE_NAME)) { appName = obj.getJson().optString(ANDROID_PACKAGE_NAME); } else { appName = "Unknown"; } if (!(obj instanceof DbObj)) { if (appName.contains(".")) { appName = appName.substring(appName.lastIndexOf(".") + 1); } String text = "Preparing application " + appName + "..."; // TODO: Show Market icon or app icon. TextView valueTV = new TextView(context); valueTV.setText(text); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); return; } DbObj dbParentObj = (DbObj) obj; boolean rendered = false; Intent launch = getLaunchIntent(context, dbParentObj); List<ResolveInfo> infos = pm.queryIntentActivities(launch, 0); if (infos.size() > 0) { ResolveInfo info = infos.get(0); if (info.activityInfo.labelRes != 0) { appName = info.activityInfo.loadLabel(pm).toString(); icon = info.loadIcon(pm); } else { appName = info.activityInfo.name; } } else { appName = obj.getJson().optString(ANDROID_PACKAGE_NAME); if (appName.contains(".")) { appName = appName.substring(appName.lastIndexOf(".") + 1); } } // TODO: Safer reference to containing view if (icon != null) { View parentView = (View) frame.getParent().getParent(); ImageView avatar = (ImageView) parentView.findViewById(R.id.icon); avatar.setImageDrawable(icon); TextView label = (TextView) parentView.findViewById(R.id.name_text); label.setText(appName); } // TODO: obj.getLatestChild().render(); String selection = getRenderableClause(); String[] selectionArgs = null; Cursor cursor = dbParentObj.getSubfeed().query(selection, selectionArgs); if (cursor.moveToFirst()) { DbObj dbObj = App.instance().getMusubi().objForCursor(cursor); DbObjects.getFeedRenderer(dbObj.getType()).render(context, frame, dbObj, allowInteractions); rendered = true; } if (!rendered) { String text; if (icon != null) { ImageView iv = new ImageView(context); iv.setImageDrawable(icon); iv.setAdjustViewBounds(true); iv.setMaxWidth(60); iv.setMaxHeight(60); iv.setLayoutParams(CommonLayouts.WRAPPED); frame.addView(iv); text = appName; } else { text = "New application: " + appName + "."; } // TODO: Show Market icon or app icon. TextView valueTV = new TextView(context); valueTV.setText(text); 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:de.mrapp.android.dialog.decorator.WizardDialogDecorator.java
/** * Inflates the layout, which is used to show the dialog's buttons. *//*from ww w . j av a 2 s . com*/ private void inflateButtonBar() { ViewGroup rootView = (ViewGroup) getDialogRootView(); if (rootView != null) { LayoutInflater layoutInflater = LayoutInflater.from(getContext()); buttonBarContainer = (ViewGroup) layoutInflater.inflate(R.layout.button_bar_container, rootView, false); rootView.addView(buttonBarContainer); View view = layoutInflater.inflate(R.layout.horizontal_button_bar, buttonBarContainer, false); buttonBarContainer.addView(view); nextButton = (Button) view.findViewById(android.R.id.button1); finishButton = (Button) view.findViewById(android.R.id.button2); backButton = (Button) view.findViewById(android.R.id.button3); buttonBarDivider = view.findViewById(R.id.button_bar_divider); } }
From source file:com.umeng.common.ui.emoji.EmojiBorad.java
/** * init. Set params and add show emoji views</br> *///from w w w . ja v a 2 s . c om private void init() { computeBoardHeight(); setOrientation(LinearLayout.VERTICAL); setBackgroundColor(Color.parseColor("#f4f4f6")); ViewPager viewPager = createVIewpager(); addView(viewPager); ViewGroup container = createPointLinearlayout(); List<EmojiView> datas = new ArrayList<EmojiView>(); int lens = People.DATA.length; int pages = lens / PAGE_SIZE; // pages? for (int i = 0; i < pages; i++) { EmojiBean[] blocks = new EmojiBean[PAGE_SIZE + 1]; System.arraycopy(People.DATA, i * PAGE_SIZE, blocks, 0, blocks.length - 1); blocks[PAGE_SIZE] = EmojiBean.fromChars(DELETE_KEY); datas.add(new EmojiView(getContext(), blocks)); // the last is // delete icon } // add remain emoji view if (pages * PAGE_SIZE < lens) { EmojiBean[] blocks = new EmojiBean[lens - pages * PAGE_SIZE]; System.arraycopy(People.DATA, pages * PAGE_SIZE, blocks, 0, blocks.length); datas.add(new EmojiView(getContext(), blocks)); } // add indicator for (int i = 0; i < datas.size(); i++) { ImageView indicatorView = createIndicator(); mIndicators.add(indicatorView); container.addView(indicatorView); } addView(container); size = datas.size(); // set cache view count viewPager.setOffscreenPageLimit(datas.size()); // mIndicators.get(mLastSelectViewPos).setImageDrawable(ColorQueque.getDrawable(mSelectIcon)); mAdapter = new EmojiPagerAdapter(getContext(), datas); viewPager.setAdapter(mAdapter); viewPager.setOnPageChangeListener(this); }
From source file:android.support.v7.preference.PreferenceController.java
@Override @NonNull// w ww.ja v a 2 s . c o m public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @Nullable Bundle savedInstanceState) { mInitDone = false; mHavePrefs = false; final TypedValue tv = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true); final int theme = tv.resourceId; if (theme == 0) { throw new IllegalStateException("Must specify preferenceTheme in theme"); } mStyledContext = new ContextThemeWrapper(getActivity(), theme); mPreferenceManager = new PreferenceManager(mStyledContext); final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT); onCreatePreferences(savedInstanceState, rootKey); TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat, R.attr.preferenceFragmentCompatStyle, 0); mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId); mDividerDecoration = new DividerDecoration(); final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider); final int dividerHeight = a .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1); final boolean allowDividerAfterLastItem = a .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true); a.recycle(); final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme); final LayoutInflater themedInflater = inflater.cloneInContext(themedContext); final View view = themedInflater.inflate(mLayoutResId, container, false); final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER); if (!(rawListContainer instanceof ViewGroup)) { throw new RuntimeException("Content has view with id attribute " + "'android.R.id.list_container' that is not a ViewGroup class"); } final ViewGroup listContainer = (ViewGroup) rawListContainer; final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState); if (listView == null) { throw new RuntimeException("Could not create RecyclerView"); } mList = listView; listView.addItemDecoration(mDividerDecoration); setDivider(divider); if (dividerHeight != -1) { setDividerHeight(dividerHeight); } mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem); listContainer.addView(mList); mHandler.post(mRequestFocus); onViewCreated(view, savedInstanceState); return view; }
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Adds an action bar button to the compatibility action bar (on phones). */// w w w . ja v a2s . c o m private View addActionButtonCompat(int iconResId, int textResId, View.OnClickListener clickListener, boolean separatorAfter) { final ViewGroup actionBar = getActionBarCompat(); if (actionBar == null) { return null; } // Create the separator ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle); separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT)); // Create the button ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle); actionButton.setLayoutParams(new ViewGroup.LayoutParams( (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT)); actionButton.setImageResource(iconResId); actionButton.setScaleType(ImageView.ScaleType.CENTER); actionButton.setContentDescription(mActivity.getResources().getString(textResId)); actionButton.setOnClickListener(clickListener); // Add separator and button to the action bar in the desired order if (!separatorAfter) { actionBar.addView(separator); } actionBar.addView(actionButton); if (separatorAfter) { actionBar.addView(separator); } return actionButton; }
From source file:com.grokkingandroid.sampleapp.samples.data.contentprovider.about.AboutFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setTitle(getResources().getString(R.string.cpsample_about)); View view = inflater.inflate(R.layout.fragment_about, container, false); ViewGroup libParent = (ViewGroup) view.findViewById(R.id.about_container); String[] libTitles = getResources().getStringArray(R.array.cpsample_about_titles); String[] libDescriptions = getResources().getStringArray(R.array.cpsample_about_contents); String libraryPlural = getResources().getQuantityString(R.plurals.cpsample_libraries_plural, libTitles.length);//from w w w. j av a 2 s. c o m String aboutText = getResources().getString(R.string.cpsample_about_text, libraryPlural); Spanned spannedAboutText = Html.fromHtml(aboutText); TextView aboutTv = (TextView) libParent.findViewById(R.id.about_text); aboutTv.setText(spannedAboutText); aboutTv.setMovementMethod(LinkMovementMethod.getInstance()); for (int i = 0; i < libTitles.length; i++) { View libContainer = inflater.inflate(R.layout.single_library_layout, libParent, false); TextView currLibTitle = (TextView) libContainer.findViewById(R.id.library_title); currLibTitle.setText(libTitles[i]); TextView currLibDesc = (TextView) libContainer.findViewById(R.id.library_text); Spanned spanned = Html.fromHtml(libDescriptions[i]); currLibDesc.setText(spanned); currLibDesc.setMovementMethod(LinkMovementMethod.getInstance()); libParent.addView(libContainer); } return view; }
From source file:com.sweetiepiggy.littlepro.SubmitQuizFragment.java
private boolean update(Map<Long, String> questionIdAndCorrectAnswers) { View view = getView();//from w w w.ja v a2s .c o m if (view == null) { boolean allowUnlock = false; return allowUnlock; } ViewGroup questionsLayout = (ViewGroup) view.findViewById(R.id.questions_layout); mAnswerViews.clear(); questionsLayout.removeAllViews(); int correctPoints = 0; int totalPoints = 0; for (Pair<Question, String> questionAndAnswer : mSubmitQuizListener.getQuestionAndAnswers()) { Question question = questionAndAnswer.first; String answer = questionAndAnswer.second; String correctAnswer = null; int points = question.getPoints(); totalPoints += points; if (questionIdAndCorrectAnswers != null) { correctAnswer = questionIdAndCorrectAnswers.get(question.getId()); } TextView answerView = new TextView(getActivity()); if (mSubmitted) { if (answer.equals(correctAnswer)) { answerView.setText(answer + ": Correct"); correctPoints += points; } else { answerView.setText(answer + ": Wrong"); } } else { answerView.setText(answer); } mAnswerViews.add(answerView); questionsLayout.addView(answerView); mQuestionIdAndAnswers.put(question.getId(), answer); } if (mSubmitted) { view.findViewById(R.id.submit_button).setVisibility(View.GONE); } double percentCorrect = (totalPoints == 0) ? 0. : (100. * correctPoints) / totalPoints; boolean allowUnlock = percentCorrect >= 75.; return allowUnlock; }
From source file:com.pikachu.emoji.widget.EmojiView.java
/** * init. Set params and add show emoji views</br> *//*from www . ja v a2 s . co m*/ @SuppressWarnings("deprecation") private void init() { computeBoardHeight(); setOrientation(LinearLayout.VERTICAL); setBackgroundColor(Color.parseColor("#f4f4f6")); ViewPager viewPager = createVIewpager(); addView(viewPager); ViewGroup container = createPointLinearlayout(); List<EmojiPage> datas = new ArrayList<EmojiPage>(); int lens = EmojiSource.DATA.length; int pages = lens / PAGE_SIZE; // pages? for (int i = 0; i < pages; i++) { EmojiBean[] blocks = new EmojiBean[PAGE_SIZE + 1]; System.arraycopy(EmojiSource.DATA, i * PAGE_SIZE, blocks, 0, blocks.length - 1); blocks[PAGE_SIZE] = EmojiBean.fromChars(DELETE_KEY); datas.add(new EmojiPage(getContext(), blocks)); // the last is // delete icon } // add remain emoji view if (pages * PAGE_SIZE < lens) { EmojiBean[] blocks = new EmojiBean[lens - pages * PAGE_SIZE]; System.arraycopy(EmojiSource.DATA, pages * PAGE_SIZE, blocks, 0, blocks.length); datas.add(new EmojiPage(getContext(), blocks)); } // add indicator for (int i = 0; i < datas.size(); i++) { ImageView indicatorView = createIndicator(); mIndicators.add(indicatorView); container.addView(indicatorView); } addView(container); // set cache view count viewPager.setOffscreenPageLimit(datas.size()); // mIndicators.get(mLastSelectViewPos).setImageDrawable(ResFinder.getDrawable(mSelectIcon)); mAdapter = new EmojiPagerAdapter(getContext(), datas); viewPager.setAdapter(mAdapter); viewPager.setOnPageChangeListener(this); }