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:ca.rmen.android.palidamuerte.app.poem.list.PoemListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ListView listView = getListView();
    ViewGroup parent = (ViewGroup) listView.getParent();
    final View emptyListView;
    String searchTerms = getActivity().getIntent().getStringExtra(SearchManager.QUERY);
    if (!TextUtils.isEmpty(searchTerms)) {
        emptyListView = getActivity().getLayoutInflater().inflate(R.layout.empty_search_list, parent, false);
        String[] keyWords = Search.getSearchTerms(searchTerms);
        ((TextView) emptyListView.findViewById(R.id.empty_search_list_description)).setText(getResources()
                .getQuantityString(R.plurals.empty_search_list_description, keyWords.length, searchTerms));

    } else {//from   www. j a v a 2s  .com
        emptyListView = getActivity().getLayoutInflater().inflate(R.layout.empty_favorite_list, parent, false);
    }
    TextView emptyTitle = (TextView) emptyListView.findViewById(R.id.title);
    emptyTitle.setTypeface(Font.getTypeface(getActivity()));
    parent.addView(emptyListView);
    listView.setEmptyView(emptyListView);

    // Restore the previously serialized activated item position.
    if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
        setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
    }
}

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

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from ww  w  .  j a va 2  s .c o  m*/
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.play);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);
    valueTV.setText(asText(content));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);

    container.addView(imageView);
    container.addView(valueTV);
    frame.addView(container);
}

From source file:com.alex.vmandroid.display.main.fragments.fragments.LoopAdvertisementAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(mContext).inflate(com.alex.view.R.layout.banner_item, container, false);
    final ImageView imageView = (ImageView) view.findViewById(com.alex.view.R.id.iv_banner_item);
    // ???// ww w .j  a v a2 s  .c  o m
    position %= pictureList.size();

    //imageView.setImageResource(pictureList.get(position));
    final int p = position;
    new DownloadPic().getById(pictureList.get(position), new DownloadPic.Listener() {
        @Override
        public void succeed(final Bitmap bm) {
            handler.post(new Runnable() {
                @Override
                public void run() {

                    AppLog.debug("positiont",
                            pictureList.get(p).toString() + " " + pictureList.size() + "+" + p);

                    imageView.setImageBitmap(bm);
                }
            });

        }

        @Override
        public void failed() {

        }
    });
    container.addView(view);
    return view;
}

From source file:com.egoclean.testpregnancy.util.ActivityHelper.java

/**
 * Sets up the action bar with the given title and accent color. If title is null, then
 * the app logo will be shown instead of a title. Otherwise, a home button and title are
 * visible. If color is null, then the default colorstrip is visible.
 *//*from ww w .j  a  v a 2 s. co m*/
public void setupActionBar(CharSequence title, int color) {
    final ViewGroup actionBarCompat = getActionBarCompat();
    if (actionBarCompat == null) {
        return;
    }

    LinearLayout.LayoutParams springLayoutParams = new LinearLayout.LayoutParams(0,
            ViewGroup.LayoutParams.FILL_PARENT);
    springLayoutParams.weight = 1;

    View.OnClickListener homeClickListener = new View.OnClickListener() {
        public void onClick(View view) {
            goHome();
        }
    };

    if (title != null) {
        // Add Home button
        addActionButtonCompat(R.drawable.ic_title_home, R.string.description_home, homeClickListener, true);
    } else {
        // Add logo
        ImageButton logo = new ImageButton(mActivity, null, R.attr.actionbarCompatLogoStyle);
        logo.setOnClickListener(homeClickListener);
        actionBarCompat.addView(logo);
    }

    // Add title text
    TextView titleText = new TextView(mActivity, null, R.attr.actionbarCompatTextStyle);
    titleText.setLayoutParams(springLayoutParams);
    titleText.setText(title);
    actionBarCompat.addView(titleText);

    setActionBarColor(color);
}

From source file:com.javielinux.utils.SplitActionBarMenu.java

public void loadSplitActionBarMenu(ViewGroup root) {
    View splitActionBarMenu = activity.getLayoutInflater().inflate(R.layout.split_action_bar_menu, null);

    root_layout = (LinearLayout) splitActionBarMenu.findViewById(R.id.split_action_bar_menu_root);
    scroll_view_layout = (HorizontalScrollView) splitActionBarMenu
            .findViewById(R.id.split_action_bar_menu_scroll_view);
    main_layout = (LinearLayout) splitActionBarMenu.findViewById(R.id.split_action_bar_menu_container);
    root_layout.setOnClickListener(new View.OnClickListener() {
        @Override//from   w ww  .  j ava  2s  .  c om
        public void onClick(View view) {
            hideSplitActionBarMenu();
        }
    });

    ThemeManager themeManager = new ThemeManager(activity);
    themeManager.setTheme();
    scroll_view_layout.setBackgroundDrawable(
            ImageUtils.createBackgroundDrawable(activity, themeManager.getColor("color_top_bar"), false, 0));

    root.addView(splitActionBarMenu);
}

From source file:com.appsimobile.appsii.AbstractSidebarPagerAdapter.java

@Override
public final Object instantiateItem(ViewGroup container, int position) {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    PageController controller = mActivePageControllers.get(position);

    if (controller == null) {
        HotspotPageEntry page = mActivePageKeys.get(position);
        controller = instantiateAndCacheControllerForPage(page);
    }/*from  ww w . j  a va 2  s. c  o m*/

    HotspotPageEntry page = mActivePageKeys.get(position);
    controller.setPage(page);

    Bundle state = mSavedControllerStates.get(page);
    controller.performCreate(state);

    View result = controller.performCreateView(inflater, container);
    controller.performViewCreated(result);

    if (mAttachedToWindow) {
        controller.onSidebarAttached();
    } else {
        controller.onSidebarDetached();
    }

    container.addView(controller.getView());
    controller.performOnAttach();
    controller.performStart();
    controller.performRestoreInstanceState();
    controller.performResume();

    return controller;
}

From source file:com.google.android.apps.dashclock.configuration.ConfigureAppearanceFragment.java

private void configureStylePager(final ViewPager pager, final PagerPositionStrip positionStrip,
        final String[] styleNames, final String styleComponent, final int gravity, final String preference) {
    String currentStyleName = mCurrentStyleNames.get(preference);

    final LayoutInflater inflater = getActivity().getLayoutInflater();
    pager.setAdapter(new PagerAdapter() {
        @Override//  www  .  j ava 2s. c  om
        public int getCount() {
            return styleNames.length;
        }

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

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            FrameLayout wrapper = new FrameLayout(getActivity());
            ViewPager.LayoutParams wrapperLp = new ViewPager.LayoutParams();
            wrapper.setLayoutParams(wrapperLp);
            String styleName = styleNames[position];
            if (styleName.contains("analog")) {
                styleName += "_white";
            }
            View v = inflater.inflate(
                    AppearanceConfig.getLayoutByStyleName(getActivity(), styleComponent, styleName), container,
                    false);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.gravity = gravity;
            v.setLayoutParams(lp);
            wrapper.addView(v);
            container.addView(wrapper);
            return wrapper;
        }

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

    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            mCurrentStyleNames.put(preference, styleNames[position]);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            positionStrip.setPosition(position + positionOffset);
        }
    });

    positionStrip.setPageCount(styleNames.length);

    pager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                showPositionStrips(true, -1);
                break;

            case MotionEvent.ACTION_UP:
                showPositionStrips(false, AUTO_HIDE_DELAY_MILLIS);
                break;
            }
            return false;
        }
    });

    for (int i = 0; i < styleNames.length; i++) {
        if (currentStyleName.equals(styleNames[i])) {
            pager.setCurrentItem(i);
            positionStrip.setPosition(i);
            break;
        }
    }
}

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

public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/* w w  w.j av a  2  s . co m*/
    // TODO: hack to show object history in app feeds
    SignedObj appState = getAppStateForChildFeed(context, obj);
    if (appState != null) {
        mAppStateObj.render(context, frame, obj, allowInteractions);
        return;
    } else {
        String appName = content.optString(PACKAGE_NAME);
        if (appName.contains(".")) {
            // TODO: look up label.
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Welcome to " + appName + "!";
        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:com.javielinux.utils.PopupLinks.java

public void loadPopup(ViewGroup root) {
    View popupLinks = activity.getLayoutInflater().inflate(R.layout.popup_links, null);

    layoutMainLinks = (LinearLayout) popupLinks.findViewById(R.id.tweettopics_ll_main_links);
    layoutMainLinks.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w  w .  ja v a 2  s. com*/
        public void onClick(View view) {
            hideLinks();
        }
    });

    layoutLinks = (LinearLayout) popupLinks.findViewById(R.id.tweettopics_ll_links);

    linksAdapter = new LinksAdapter(activity, activity.getSupportLoaderManager(), links);
    gvLinks = (GridView) popupLinks.findViewById(R.id.tweettopics_gv_links);
    gvLinks.setAdapter(linksAdapter);
    gvLinks.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            goToLink(links.get(i));
        }
    });

    root.addView(popupLinks);
}

From source file:com.calciumion.widget.BasePagerAdapter.java

@Override
public final void finishUpdate(ViewGroup container) {
    ArrayList<View> recycledViews = new ArrayList<View>();

    // Remove views backing destroyed items from the specified container,
    // and queue them for recycling.
    for (int i = 0; destroyedItems.size() > 0 && i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        Iterator<Object> it = destroyedItems.iterator();
        while (it.hasNext()) {
            if (isViewFromObject(v, it.next())) {
                container.removeView(v);
                recycledViews.add(v);/*from   w  w w . j av  a 2s .co  m*/
                it.remove();
                break;
            }
        }
    }

    // Render views and attach them to the container. Page views are reused
    // whenever possible.
    for (Object instantiatedItem : instantiatedItems) {
        View convertView = null;
        if (recycledViews.size() > 0)
            convertView = recycledViews.remove(0);
        convertView = getView(instantiatedItem, convertView, container);
        convertView.setTag(instantiatedItem);
        container.addView(convertView);
    }

    instantiatedItems.clear();
    recycledViews.clear();
}