List of usage examples for android.view ViewGroup addView
public void addView(View child)
Adds a child view.
From source file:com.github.pennyfive.sqlitestudio.ui.PackagesFragment.java
@Override public void onLoadFinished(Loader<Result> resultLoader, Result result) { TextView databaseCountHeader = (TextView) View.inflate(getActivity(), R.layout.header_text, null); databaseCountHeader.setText(getResources().getQuantityString(R.plurals.databases_header_num_databases, result.getTotalNumDatabases(), result.getTotalNumDatabases())); listView.addHeaderView(databaseCountHeader, null, false); listView.setAdapter(new BinderAdapter<ScannedPackage>(getActivity(), result.getScannedPackages()) { @Override/*from w w w .j a v a2 s . c om*/ protected View newView(LayoutInflater inflater, ViewGroup parent) { return inflater.inflate(R.layout.item_package, parent, false); } @Override protected void bindView(View view, final ScannedPackage item, int position) { Drawable applicationIcon = getApplicationIcon(item.getPackageName()); ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(applicationIcon); String applicationName = getApplicationName(item.getPackageName()); ((TextView) view.findViewById(R.id.application_name)).setText(applicationName); ((TextView) view.findViewById(R.id.package_name)).setText(item.getPackageName()); ((TextView) view.findViewById(R.id.num_databases)).setText(String.valueOf(item.getNumDatabases())); final ViewGroup databaseLayout = (ViewGroup) view.findViewById(R.id.database_layout); databaseLayout.removeAllViews(); final LayoutInflater inflater = LayoutInflater.from(getActivity()); final int databasesCount = item.getNumDatabases(); int initialItemCount = databasesCount > NUM_DATABASES_WHEN_COLLAPSED + 1 ? NUM_DATABASES_WHEN_COLLAPSED : databasesCount; for (int i = 0; i < initialItemCount; i++) { databaseLayout .addView(inflateDatabaseItem(inflater, databaseLayout, item.getDatabasePaths().get(i))); } if (databasesCount > initialItemCount) { View showAllFooter = inflater.inflate(R.layout.item_package_show_all_extra, null); databaseLayout.addView(showAllFooter); showAllFooter.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { databaseLayout.removeView(v); for (int i = databaseLayout.getChildCount(); i < databasesCount; i++) { databaseLayout.addView(inflateDatabaseItem(inflater, databaseLayout, item.getDatabasePaths().get(i))); } } }); } } private View inflateDatabaseItem(LayoutInflater inflater, ViewGroup parent, final String databasePath) { View databaseItem = inflater.inflate(R.layout.item_package_database_extra, parent, false); String databaseFileName = databasePath.substring(databasePath.lastIndexOf('/') + 1, databasePath.length()); ((TextView) databaseItem.findViewById(R.id.text)).setText(databaseFileName); databaseItem.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onDatabaseSelected(databasePath); } }); return databaseItem; } }); }
From source file:com.github.pockethub.android.ui.WelcomePagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { View v = LayoutInflater.from(container.getContext()).inflate(view, container, false); TextView titleText = ((TextView) v.findViewById(R.id.tv_title)); TextView infoText = ((TextView) v.findViewById(R.id.tv_info)); titleText.setText(titles[position]); infoText.setText(info[position]);//w w w. j av a 2 s .c om if (position == 0) { @ColorInt int primaryColor = titleText.getResources().getColor(R.color.primary); titleText.setTextColor(primaryColor); infoText.setTextColor(primaryColor); } ((ImageView) v.findViewById(R.id.iv_art)).setImageResource(images[position]); container.addView(v); return v; }
From source file:com.pedrogomez.renderers.VPRendererAdapter.java
/** * Main method of VPRendererAdapter. This method has the responsibility of update the * RendererBuilder values and create or recycle a new Renderer. Once the renderer has been * obtained the RendereBuilder will call the render method in the renderer and will return the * Renderer root view to the ViewPager./*from w w w.ja va 2s . com*/ * * If RendererBuilder returns a null Renderer this method will throw a * NullRendererBuiltException. * * @param parent The containing View in which the page will be shown. * @param position to render. * @return view rendered. */ @Override public Object instantiateItem(ViewGroup parent, int position) { T content = getItem(position); rendererBuilder.withContent(content); rendererBuilder.withParent(parent); rendererBuilder.withLayoutInflater(LayoutInflater.from(parent.getContext())); Renderer<T> renderer = rendererBuilder.build(); if (renderer == null) { throw new NullRendererBuiltException("RendererBuilder have to return a not null Renderer"); } updateRendererExtraValues(content, renderer, position); renderer.render(); View view = renderer.getRootView(); parent.addView(view); return view; }
From source file:com.finchuk.clock2.ringtone.TimesUpActivity.java
@Override protected void getHeaderContent(ViewGroup parent) { // Inflate the content and apply the parent's layout params, but don't // attach it to the parent yet. This is so the return value can be // the root of the inflated content, and not the parent. Alternatively, // we could set an id on the root of the content's layout and find it // from the returned parent. CountdownChronometer countdown = (CountdownChronometer) getLayoutInflater() .inflate(com.finchuk.clock2.R.layout.content_header_timesup_activity, parent, false); countdown.setBase(SystemClock.elapsedRealtime()); countdown.start();/* ww w.j a v a2s . c om*/ parent.addView(countdown); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LocationObj.java
@Override public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();/*from w ww .j a va2 s. co m*/ TextView valueTV = new TextView(context); NumberFormat df = DecimalFormat.getNumberInstance(); df.setMaximumFractionDigits(5); df.setMinimumFractionDigits(5); String msg = "I'm at " + df.format(content.optDouble(COORD_LAT)) + ", " + df.format(content.optDouble(COORD_LONG)); valueTV.setText(msg); 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.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { LayoutInflater inflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mParentView = inflater.inflate(R.layout.rgb_view_landscape, null); ViewGroup rootViewG = (ViewGroup) getView(); // Remove all the existing views from the root view. try {/* w ww .j a v a 2 s . co m*/ assert rootViewG != null; rootViewG.removeAllViews(); rootViewG.addView(mParentView); } catch (Exception e) { e.printStackTrace(); } } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { LayoutInflater inflater = (LayoutInflater) getActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mParentView = inflater.inflate(R.layout.rgb_view_portrait, null); ViewGroup rootViewG = (ViewGroup) getView(); // Remove all the existing views from the root view. try { assert rootViewG != null; rootViewG.removeAllViews(); rootViewG.addView(mParentView); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.taobao.weex.ui.view.WXCirclePageAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { View pageView = null;/* ww w . ja v a2 s . c o m*/ try { pageView = shadow.get(position); if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("onPageSelected >>>> instantiateItem >>>>> position:" + position + ",position % getRealCount()" + position % getRealCount()); } if (pageView.getParent() == null) { container.addView(pageView); } else { ((ViewGroup) pageView.getParent()).removeView(pageView); container.addView(pageView); } } catch (Exception e) { WXLogUtils.e("[CirclePageAdapter] instantiateItem: ", e); } return pageView; }
From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java
public void createNoEntriesCard(ViewGroup parent, LayoutInflater inflater) { LinearLayout wrapper = new LinearLayout(parent.getContext()); wrapper.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); setOrientationPadding(wrapper);/* w w w. ja v a2 s .c o m*/ CardView cv = (CardView) inflater.inflate(R.layout.basic_cardview, wrapper, false); createPrimaryTextView(getResources().getString(R.string.no_entries), 20, inflater, cv); wrapper.addView(cv); parent.addView(wrapper); }
From source file:com.silentcircle.contacts.editor.RawContactEditorView.java
/** * Set the internal state for this view, given a current * {@link RawContactDelta} state and the {@link com.silentcircle.contacts.model.account.AccountType} that * apply to that state.//from ww w . j av a 2s .c om */ @Override public void setState(RawContactDelta state, AccountType type, ViewIdGenerator vig, boolean isProfile) { mState = state; // Remove any existing sections mFields.removeAllViews(); // Bail if invalid state or account type if (state == null || type == null) return; setId(vig.getId(state, null, null, ViewIdGenerator.NO_VIEW_INDEX)); // Make sure we have a StructuredName and Organization RawContactModifier.ensureKindExists(state, type, StructuredName.CONTENT_ITEM_TYPE); RawContactModifier.ensureKindExists(state, type, Organization.CONTENT_ITEM_TYPE); mRawContactId = state.getRawContactId(); // Show photo editor when supported RawContactModifier.ensureKindExists(state, type, Photo.CONTENT_ITEM_TYPE); setHasPhotoEditor((type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null)); getPhotoEditor().setEnabled(isEnabled()); mName.setEnabled(isEnabled()); mPhoneticName.setEnabled(isEnabled()); // Show and hide the appropriate views mFields.setVisibility(VISIBLE); mName.setVisibility(VISIBLE); mPhoneticName.setVisibility(VISIBLE); mGroupMembershipKind = type.getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE); if (mGroupMembershipKind != null) { mGroupMembershipView = (GroupMembershipView) mInflater.inflate(R.layout.item_group_membership, mFields, false); mGroupMembershipView.setParent(parent); mGroupMembershipView.setKind(mGroupMembershipKind); mGroupMembershipView.setEnabled(isEnabled()); } // Create editor sections for each possible data kind for (DataKind kind : type.getSortedDataKinds()) { // Skip kind of not editable if (!kind.editable) continue; final String mimeType = kind.mimeType; if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) { // Handle special case editor for structured name final RawContactDelta.ValuesDelta primary = state.getPrimaryEntry(mimeType); mName.setValues(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME), primary, state, false, vig); mPhoneticName.setValues(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME), primary, state, false, vig); } else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) { // Handle special case editor for photos final RawContactDelta.ValuesDelta primary = state.getPrimaryEntry(mimeType); getPhotoEditor().setValues(kind, primary, state, false, vig); } else if (GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType)) { if (mGroupMembershipView != null) { mGroupMembershipView.setState(state); } } else if (Organization.CONTENT_ITEM_TYPE.equals(mimeType)) { // Create the organization section final KindSectionView section = (KindSectionView) mInflater.inflate(R.layout.item_kind_section, mFields, false); section.setTitleVisible(false); section.setEnabled(isEnabled()); section.setState(kind, state, false, vig); // If there is organization info for the contact already, display it if (!section.isEmpty()) { mFields.addView(section); } else { // Otherwise provide the user with an "add organization" button that shows the // EditText fields only when clicked final View organizationView = mInflater.inflate(R.layout.organization_editor_view_switcher, mFields, false); final View addOrganizationButton = organizationView.findViewById(R.id.add_organization_button); final ViewGroup organizationSectionViewContainer = (ViewGroup) organizationView .findViewById(R.id.container); organizationSectionViewContainer.addView(section); // Setup the click listener for the "add organization" button addOrganizationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Once the user expands the organization field, the user cannot // collapse them again. organizationSectionViewContainer.setVisibility(VISIBLE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { EditorAnimator.getInstance().expandOrganization(addOrganizationButton, organizationSectionViewContainer); } else { addOrganizationButton.setVisibility(INVISIBLE); } } }); mFields.addView(organizationView); } } else { // Otherwise use generic section-based editors if (kind.fieldList == null) continue; final KindSectionView section = (KindSectionView) mInflater.inflate(R.layout.item_kind_section, mFields, false); section.setEnabled(isEnabled()); section.setState(kind, state, false, vig); mFields.addView(section); } } if (mGroupMembershipView != null) { mFields.addView(mGroupMembershipView); } updatePhoneticNameVisibility(); addToDefaultGroupIfNeeded(); final int sectionCount = getSectionViewsWithoutFields().size(); mAddFieldButton.setVisibility(sectionCount > 0 ? VISIBLE : GONE); mAddFieldButton.setEnabled(isEnabled()); }
From source file:com.yojiokisoft.japanesecalc.SkinPagerAdapter.java
/** * @see PagerAdapter#instantiateItem(ViewGroup, int) *///from w ww . ja va2 s . com @Override public Object instantiateItem(ViewGroup container, int position) { FrameLayout layout = (FrameLayout) this.mInflter.inflate(R.layout.page_skin, null); mBigImage = (ImageView) layout.findViewById(R.id.big_image); int padding = MyResource.dpi2Px(5); if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mBigImage.setPadding(0, 0, padding, 0); } else { mBigImage.setPadding(0, padding, 0, 0); } BackImageEntity item = mList.get(position); String resName = item.resourceName; int resId = MyResource.getResourceIdByName(resName); mBigImage.setImageResource(resId); mBigImage.setTag(resName); // ? container.addView(layout); return layout; }