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.beck.matthew.customtabs.TabPagerAdapter.java

public Object instantiateItem(ViewGroup collection, int position) {
    PagerEnum pagerEnum = PagerEnum.values()[position];
    LayoutInflater inflater = LayoutInflater.from(mContext);
    ViewGroup layout;/*from  w  ww  .  j  a  va2 s  . com*/
    if (layouts[position] != null) {
        layout = layouts[position];// Here its just set to the previouse layout that was inflated
    } else {
        layout = (ViewGroup) inflater.inflate(pagerEnum.getLayoutResId(), collection, false);// inflates the layout
        layouts[position] = layout;// saves the layout in the array
        /*
        Here place any ListView adapters and initalize them.
        This is because of some bugs. Adapters that are updated in another class will have to have a static adapter
        */
    }
    collection.addView(layout);
    return layout;
}

From source file:com.bruce.study.demo.studydata.viewpage.ViewPagerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    LayoutInflater inflater = getLayoutInflater();
    pageViews = new ArrayList<>(5);
    pageViews.add(inflater.inflate(R.layout.viewpager_item_01, null));
    pageViews.add(inflater.inflate(R.layout.viewpager_item_02, null));
    pageViews.add(inflater.inflate(R.layout.viewpager_item_03, null));
    pageViews.add(inflater.inflate(R.layout.viewpager_item_04, null));

    imageViews = new ImageView[pageViews.size()];
    ViewGroup main = (ViewGroup) inflater.inflate(R.layout.viewpager_activity, null);
    ViewGroup group = (ViewGroup) main.findViewById(R.id.ll_viewgroup);
    ViewPager viewPager = (ViewPager) main.findViewById(R.id.vp_guide);
    for (int i = 0; i < pageViews.size(); i++) {
        ImageView imageView = new ImageView(ViewPagerActivity.this);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(20, 20));
        imageView.setPadding(20, 0, 20, 0);
        imageViews[i] = imageView;/*  w w w .j  av  a 2  s  . co  m*/
        if (i == 0) {
            imageViews[i].setBackgroundResource(R.drawable.viewpager_indicator_focused);
        } else {
            imageViews[i].setBackgroundResource(R.drawable.viewpage_indicator);
        }
        group.addView(imageViews[i]);
    }
    setContentView(main);
    viewPager.setAdapter(new MyViewPagerAdapter());
    viewPager.setOnPageChangeListener(new PageChangeListener());
}

From source file:com.sitewhere.android.example.ExampleFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup example = (ViewGroup) inflater.inflate(R.layout.example, container, false);

    View map = super.onCreateView(inflater, example, savedInstanceState);
    FrameLayout.LayoutParams mapParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    map.setLayoutParams(mapParams);/*  www .  j a v a 2s. co m*/
    example.addView(map);

    View overlay = inflater.inflate(R.layout.sensor_overlay, example, false);
    FrameLayout.LayoutParams overlayParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    overlay.setLayoutParams(overlayParams);
    example.addView(overlay);

    startDeviceMonitoring();

    return example;
}

From source file:com.itude.mobile.mobbl.core.controller.util.MBBasicViewController.java

/**
 * Looks up the {@link MBPage} associated with this instance and sets the view property with a fresh view hierarchy constructed from the page definition.
 * //ww w  .  j  av  a 2  s.  c o m
 * @param contentViewNeedsToBeSet boolean indicating if the content view needs to be set during rebuild
 */
public void rebuildView(final boolean contentViewNeedsToBeSet) {
    // it is possible for the fragment to get detached in the meantime,
    // so cache the activity
    final Activity activity = getActivity();
    if (activity == null)
        return;
    MBPage page = getPage();
    page.rebuildView();

    MBThread runnable = new MBThread(page) {
        @Override
        public void runMethod() {
            if (contentViewNeedsToBeSet) {
                ViewGroup fragmentContainer = (ViewGroup) getView();

                if (fragmentContainer != null) {
                    fragmentContainer.removeAllViews();

                    ViewGroup view = buildInitialView(LayoutInflater.from(activity));

                    fragmentContainer.addView(view);
                    _contentView = view;
                } else
                    Log.w(Constants.APPLICATION_NAME, "Failed to refresh view for page "
                            + getPage().getPageName() + ", has the activity been created?");
            }
        }
    };
    activity.runOnUiThread(runnable);
}

From source file:app.newbee.lib.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;// ww w . j a  v a2  s .  c o m
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.gh4a.activities.GistActivity.java

private void fillData(final Gist gist) {
    mGist = gist;//  w ww. j a v a 2 s  .  c om

    if (gist.getOwner() != null) {
        getSupportActionBar().setSubtitle(gist.getOwner().getLogin());
    }

    TextView tvDesc = (TextView) findViewById(R.id.tv_desc);
    tvDesc.setText(TextUtils.isEmpty(gist.getDescription()) ? getString(R.string.gist_no_description)
            : gist.getDescription());

    TextView tvCreatedAt = (TextView) findViewById(R.id.tv_created_at);
    tvCreatedAt.setText(StringUtils.formatRelativeTime(this, gist.getCreatedAt(), true));

    Map<String, GistFile> files = gist.getFiles();
    if (files != null && !files.isEmpty()) {
        ViewGroup container = (ViewGroup) findViewById(R.id.file_container);
        LayoutInflater inflater = getLayoutInflater();

        container.removeAllViews();
        for (GistFile gistFile : files.values()) {
            TextView rowView = (TextView) inflater.inflate(R.layout.selectable_label, container, false);

            rowView.setText(gistFile.getFilename());
            rowView.setTextColor(UiUtils.resolveColor(this, android.R.attr.textColorPrimary));
            rowView.setOnClickListener(this);
            rowView.setTag(gistFile);
            container.addView(rowView);
        }
    } else {
        findViewById(R.id.file_card).setVisibility(View.GONE);
    }

    findViewById(R.id.tv_private).setVisibility(gist.isPublic() ? View.GONE : View.VISIBLE);
}

From source file:de.skubware.opentraining.activity.create_workout.ExerciseTypeDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_exercisetype_detail, container, false);
    ViewGroup rootLayout = (ViewGroup) rootView.findViewById(R.id.fragment_exercisetype_detail_layout);

    // If Image Exists
    if (!mExercise.getImagePaths().isEmpty()) {
        // Create Image View
        ImageView imageView = new ImageView(rootView.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setPadding(20, 20, 20, 20);
        rootLayout.addView(imageView);
        imageView.setVisibility(View.VISIBLE);

        // set gesture detector
        this.mGestureScanner = new GestureDetector(this.getActivity(),
                new ExerciseDetailOnGestureListener(this, imageView, mExercise));

        //Set Image
        DataHelper data = new DataHelper(getActivity());
        imageView.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString()));

        rootView.setOnTouchListener(new View.OnTouchListener() {
            @Override// w  ww  .ja  v a 2 s . c  o m
            public boolean onTouch(View v, MotionEvent event) {
                return mGestureScanner.onTouchEvent(event);
            }
        });
    } else {
        TextView textView = new TextView(rootView.getContext());
        textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        textView.setGravity(Gravity.CENTER);
        textView.setPadding(10, 10, 10, 10);
        textView.setText(Html.fromHtml(mExercise.getDescription()));
        rootLayout.addView(textView);
    }
    return rootView;
}

From source file:com.berniesanders.fieldthebern.adapters.AppIntroPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup viewGroup, int position) {

    LayoutInflater inflater = LayoutInflater.from(context);
    ViewGroup layout = null;/*w w  w  .  java 2 s  . c  o  m*/

    switch (position) {
    case 0:
        layout = (ViewGroup) inflater.inflate(R.layout.app_intro_page_1, viewGroup, false);
        break;
    case 1:
        layout = (ViewGroup) inflater.inflate(R.layout.app_intro_page_2, viewGroup, false);
        break;
    case 2:
        layout = (ViewGroup) inflater.inflate(R.layout.app_intro_page_3, viewGroup, false);
        break;
    case 3:
        layout = (ViewGroup) inflater.inflate(R.layout.app_intro_page_4, viewGroup, false);
        break;
    case 4:
        layout = new FrameLayout(context);
        break;
    }

    viewGroup.addView(layout);
    return layout;
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;//  w ww  .ja v a  2 s . c om
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.yojiokisoft.yumekanow.adapter.CardDetailAdapter.java

/**
 * @see PagerAdapter#instantiateItem(ViewGroup, int)
 *///from w w  w. j  a  v a2s .c o  m
@Override
public Object instantiateItem(ViewGroup container, int position) {
    FrameLayout layout = (FrameLayout) this.mInflter.inflate(R.layout.card_detail, null);

    mTextView = (TextView) layout.findViewById(R.id.affirmationText);
    mImageView = (ImageView) layout.findViewById(R.id.backImage);

    // ??
    if (mCardDao != null) {
        Integer cardId = mList.get(position);
        try {
            List<CardEntity> list = mCardDao.queryForEq("id", cardId);
            printCard(list.get(0));
        } catch (SQLException e) {
            MyUncaughtExceptionHandler.sendBugReport((Activity) mContext, e);
        }
    }

    // ?
    container.addView(layout);

    return layout;
}