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.ayo.opensource.zlayout.MainPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView;//from   www .  j  av  a 2s.co  m
    Girl girl = mAllGirlList.get(position);
    if (mAllImageMap.containsKey(position)) {
        View oldView = mAllImageMap.get(position);
        Object tag = oldView.getTag();
        if (null != tag && tag instanceof Girl) {
            if (tag.equals(girl)) {
                itemView = oldView;
                container.addView(itemView);
                return itemView;
            }
        }
        container.removeView(oldView);
        mAllImageMap.remove(position);
    }

    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    VanGogh.paper(imageView).paintMiddleImage(girl.getImageUrl(), null, null);
    //Glide.with(mContext).load(girl.getImageUrl()).into(imageView);
    imageView.setTag(girl);
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(layoutParams);
    mAllImageMap.put(position, imageView);
    itemView = imageView;
    itemView.setOnClickListener(this);
    container.addView(itemView);
    return itemView;
}

From source file:com.hayukleung.app.BaseFragment.java

/**
 * Set the content view to an explicit view. If the content view was installed earlier, the content will be replaced
 * with a new view.//from www  .  j  av  a 2s . co m
 *
 * @param view The desired content to display. Value can't be null.
 * @see #setContentView(int)
 * @see #getContentView()
 */
public void setContentView(View view) {
    ensureContent();
    if (view == null) {
        throw new IllegalArgumentException("Content view can't be null");
    }
    if (mContentContainer instanceof ViewGroup) {
        ViewGroup contentContainer = (ViewGroup) mContentContainer;
        ViewParent contentViewParent = view.getParent();
        if (contentViewParent == null) {
            if (mContentView == null) {
                contentContainer.addView(view);
            } else {
                int index = contentContainer.indexOfChild(mContentView);
                // replace content view
                contentContainer.removeView(mContentView);
                contentContainer.addView(view, index);
            }
        } else if (contentViewParent != mContentContainer) {
            throw new IllegalArgumentException("Content view can't be in other ViewGroup");
        }
        mContentView = view;
    } else {
        throw new IllegalStateException("Can't be used with a custom content view");
    }
}

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

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    ViewGroup gridDock = (ViewGroup) view.findViewById(R.id.browse_grid_dock);
    mGridViewHolder = mGridPresenter.onCreateViewHolder(gridDock);
    gridDock.addView(mGridViewHolder.view);
    mGridViewHolder.getGridView().setOnChildLaidOutListener(mChildLaidOutListener);

    updateAdapter();//from  w  ww .ja  v  a2  s. c  o  m
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public TextView createTextView(String text, int size, LayoutInflater inflater, ViewGroup group) {
    // TextView t = (TextView) inflater.inflate(R.layout.plan_text, group, true).findViewById(R.id.plan_entry);
    TextView t = new TextView(getActivity());
    t.setText(text);/*w ww.  j a v a2s .c  om*/
    t.setPadding(0, 0, toPixels(20), 0);
    t.setTextSize(size);
    group.addView(t);
    return t;
}

From source file:com.pranavpandey.smallapp.permission.PermissionWriteSystemSettings.java

private void buildPermissionsDialog() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    View view = getLayoutInflater().inflate(R.layout.sas_dialog_permission, new LinearLayout(this), false);
    ViewGroup frame = (ViewGroup) view.findViewById(R.id.permission_frame);

    String label = getApplicationInfo().loadLabel(getPackageManager()).toString();
    ((TextView) view.findViewById(R.id.permission_message)).setText(
            String.format(getString(R.string.sas_format_next_line), getString(R.string.sas_perm_request_desc),
                    String.format(getString(R.string.sas_perm_write_system_settings_info), label)));

    frame.addView(new PermissionItem(this, ContextCompat.getDrawable(this, R.drawable.sas_ic_menu_settings),
            getString(R.string.sas_perm_write_system_settings),
            getString(R.string.sas_perm_write_system_settings_desc)));

    try {//  ww  w  .j  a va2  s .  c  o  m
        alertDialogBuilder.setIcon(
                DynamicTheme.createDialogIcon(this, getPackageManager().getApplicationIcon(getPackageName())));
    } catch (Exception e) {
        e.printStackTrace();
    }
    alertDialogBuilder.setTitle(label)
            .setPositiveButton(R.string.sas_perm_continue, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    openPermissionSettings(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    finishPermissionsChecker();
                }
            }).setCancelable(false);

    final AlertDialog dialog = alertDialogBuilder.create();
    dialog.setView(view, 0, SmallUtils.getDialogTopPadding(this), 0, 0);

    showPermissionDialog(dialog);
}

From source file:com.cypress.cysmart.BLEServiceFragments.RGBFragment.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);
        rootView = inflater.inflate(R.layout.rgb_view_landscape, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        rootViewG.removeAllViews();/*  w w  w . j  a v a  2s . c  om*/
        rootViewG.addView(rootView);
        setUpControls();
        setDefaultColorPickerPositionColor();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.rgb_view_portrait, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        rootViewG.removeAllViews();
        rootViewG.addView(rootView);
        setUpControls();
        setDefaultColorPickerPositionColor();

    }

}

From source file:com.kk.binding.adapter.SimpleBindPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    viewPager = container;/*from   www.j  a v  a 2  s.  co m*/
    if (position >= mData.size())
        return null;
    BindLog.d(TAG, "instantiateItem " + "\n position = " + position + "\n data = " + mData.get(position));

    LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = layoutInflater.inflate(mResId, null);
    BindViewUtil.setDataContext(v, mData.get(position));
    container.addView(v);
    return v;
}

From source file:com.achep.base.ui.fragments.DashboardFragment.java

private void rebuildUI(Context context) {
    if (!isAdded()) {
        Log.w(TAG, "Cannot build the DashboardSummary UI yet as the Fragment is not added");
        return;/*from   w w w. j  a  v a 2  s .  c o m*/
    }

    final long start = System.currentTimeMillis();
    final Resources res = getResources();

    mDashboardContainer.removeAllViews();

    SettingsActivity activity = (SettingsActivity) context;
    List<DashboardCategory> categories = activity.getDashboardCategories(true);

    final int count = categories.size();
    for (int i = 0; i < count; i++) {
        DashboardCategory category = categories.get(i);

        View view = mLayoutInflater.inflate(R.layout.dashboard_category, mDashboardContainer, false);
        TextView labelView = (TextView) view.findViewById(R.id.category_title);
        labelView.setText(category.getTitle(res));
        mDashboardContainer.addView(view);

        ViewGroup categoryContent = (ViewGroup) view.findViewById(R.id.category_content);

        for (DashboardTile tile : category) {
            // Create, fill and add new tile to the category.
            DashboardTileView tileView = (DashboardTileView) mLayoutInflater.inflate(R.layout.dashboard_tile,
                    categoryContent, false);
            tileView.setDashboardTile(tile);
            categoryContent.addView(tileView);
        }
    }

    if (DEBUG) {
        long delta = System.currentTimeMillis() - start;
        Log.d(TAG, "Rebuilding GUI took " + delta + "ms.");
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.FeedRefObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*  www  .jav a  2 s  .  c  om*/
    byte[] raw = obj.getRaw();

    TextView view = new TextView(context);
    view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    String feedName = content.optString(FEED_ID);
    view.setText(feedName);
    view.setBackgroundColor(Feed.colorFor(feedName));
    frame.addView(view);
}

From source file:com.italankin.dictionary.ui.translation.TranslationActivity.java

/**
 * Add separate view for every attribute in array.
 *
 * @param parent     a parent view group to which views will be added
 * @param attributes array of attributes
 *//*w  w  w  .  j ava 2s.c om*/
private void addViewsForAttributes(ViewGroup parent, Attribute[] attributes) {
    LayoutInflater inflater = getLayoutInflater();
    TextView view;
    for (Attribute a : attributes) {
        view = (TextView) inflater.inflate(R.layout.item_translation_text, parent, false);
        view.setText(a.text);
        view.setOnClickListener(this);
        view.setOnLongClickListener(this);
        parent.addView(view);
    }
}