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.pranavpandey.smallapp.permission.PermissionSelectExternalStorage.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_select_external_storage_request_desc),
                    String.format(getString(R.string.sas_select_external_storage_request_info), label)));

    frame.addView(new PermissionItem(this, ContextCompat.getDrawable(this, R.drawable.sas_ic_select_storage),
            getString(R.string.sas_select_external_storage),
            getString(R.string.sas_select_external_storage_desc)));

    try {/*  w w  w .j a va2s .c  om*/
        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) {
                    triggerStorageAccessFramework();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    finish();
                }
            }).setCancelable(false);

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

    showPermissionDialog(dialog);
}

From source file:com.daniel.lupianez.casares.LayoutPagerAdapter.java

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

    //Get the resource id for that position
    int resourceId = layoutIds.get(position);
    //Inflate the view and add it to the container
    View view = View.inflate(container.getContext(), resourceId, null);

    //Tell the listener
    if ((view != null) && (onViewLoadedListener != null))
        onViewLoadedListener.onViewLoadedListener(this, view, position);

    //Add the view
    if (view != null)
        container.addView(view);

    //Finally, return the object
    return view;//  w  w  w. jav a2s . c  o  m

}

From source file:com.example.android.unsplash.ui.pager.DetailViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = layoutInflater.inflate(R.layout.detail_view, container, false);
    ThreeTwoImageView photoview = view.findViewById(R.id.photo);
    TextView authorview = view.findViewById(R.id.author);
    Photo photo = allPhotos.get(position);
    photoview.setTransitionName(String.format(photoTransitionFormat, photo.id));
    authorview.setText(photo.author);/*  w  ww  .  j  a  v a2s.  c  o  m*/
    authorview.setTransitionName(String.format(authorTransitionFormat, photo.id));
    onViewBound(photoview, photo);
    container.addView(view);
    return view;
}

From source file:com.hyperaware.conference.android.fragment.HomeFragment.java

private void populateTimeGroups(SortedMap<DateRange, List<AgendaItem>> groups, ViewGroup time_groups) {
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    for (Map.Entry<DateRange, List<AgendaItem>> entry : groups.entrySet()) {
        final ViewGroup sessions_group = (ViewGroup) inflater.inflate(R.layout.item_time_group_sessions,
                time_groups, false);/*from   w  ww . j  a va 2  s  .  co m*/
        time_groups.addView(sessions_group);

        final TextView tv_time = (TextView) sessions_group.findViewById(R.id.tv_time);
        final DateRange range = entry.getKey();
        sb.setLength(0);
        DateUtils.formatDateRange(tv_time.getContext(), formatter, range.start, range.end,
                DateUtils.FORMAT_SHOW_TIME, event.getTimezoneName());
        tv_time.setText(formatter.toString());

        final ViewGroup vg_sessions = (ViewGroup) sessions_group.findViewById(R.id.vg_sessions);
        vg_sessions.removeAllViews();
        for (final AgendaItem item : entry.getValue()) {
            final View session = inflater.inflate(R.layout.item_time_group_session, vg_sessions, false);
            vg_sessions.addView(session);
            final TextView tv_topic = (TextView) session.findViewById(R.id.tv_topic);
            tv_topic.setText(item.getTopic());
        }
    }
}

From source file:com.tecnojin.timekiller.menuviews.StatisticsAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View v = null;/*ww  w. ja v a2 s  .  c  om*/

    if (v == null) {
        v = li.inflate(R.layout.stats_page_layout, null);
        TextView t = (TextView) v.findViewById(R.id.pageNumber);
        ActivityUtil.setFont(t, ActivityUtil.FONTS_ACID_DL);
        t.setText(getPageNumber(position + 1));
        t.setVisibility(View.INVISIBLE);
        ListView ll = (ListView) v.findViewById(R.id.list);
        ll.setAdapter(new StateAdapter(c, R.layout.statitem_layout, set.getFromPage(position)));
        container.addView(v);

    }

    return v;
}

From source file:com.github.guilhermesgb.marqueeto.sample.LicensesViewPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View view = inflater.inflate(R.layout.form_drivers_license, container, false);
    final DriversLicenseForm form = new DriversLicenseForm();
    ButterKnife.bind(form, view);/*from  ww  w.j  a v  a 2 s  .  c  o  m*/
    container.addView(view);
    final DriversLicense license;
    if (position != 0) {
        license = driversLicenses.get(position - 1);
    } else {
        license = new DriversLicense();
    }
    form.nameEditText.setText(license.getName());
    form.identityNumberEditText.setText(license.getIdentityNumber());
    form.issuingOrgEditText.setText(license.getIssuingOrg());
    form.cpfNumberEditText.setText(license.getCpfNumber());
    form.cpfNumberEditText.setTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence sequence, int start, int count, int after) {
        }

        private boolean isUpdating;
        private String old = "";

        private String unmask(String s) {
            return s.replaceAll("[.]", "").replaceAll("[-]", "").replaceAll("[/]", "").replaceAll("[(]", "")
                    .replaceAll("[)]", "");
        }

        @Override
        public void onTextChanged(CharSequence sequence, int start, int before, int count) {
            String string = unmask(sequence.toString());
            String mask = "";
            if (isUpdating) {
                old = string;
                isUpdating = false;
                return;
            }
            int i = 0;
            for (char m : "###.###.###-##".toCharArray()) {
                if (m != '#' && string.length() > old.length()) {
                    mask += m;
                    continue;
                }
                try {
                    mask += string.charAt(i);
                } catch (Exception e) {
                    break;
                }
                i++;
            }
            isUpdating = true;
            form.cpfNumberEditText.setText(mask);
        }

        @Override
        public void afterTextChanged(Editable sequence) {
        }

    });
    form.birthDateEditText.setText(license.getBirthDate());
    form.filiationEditText.setText(license.getFiliation());
    form.goodThruEditText.setText(license.getGoodThru());
    form.issuingDateEditText.setText(license.getIssuingDate());
    form.locationEditText.setText(license.getLocation());
    form.saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (validateAllFieldValues(form, context.getString(R.string.label_error_value_cannot_be_empty))) {
                license.setName(form.nameEditText.getText());
                license.setIdentityNumber(form.identityNumberEditText.getText());
                license.setIssuingOrg(form.issuingOrgEditText.getText());
                license.setCpfNumber(form.cpfNumberEditText.getText());
                license.setBirthDate(form.birthDateEditText.getText());
                license.setFiliation(form.filiationEditText.getText());
                license.setGoodThru(form.goodThruEditText.getText());
                license.setIssuingDate(form.issuingDateEditText.getText());
                license.setLocation(form.locationEditText.getText());
                license.save();
                ColoredSnackbar
                        .alert(Snackbar.make(form.saveButton,
                                context.getString(R.string.snackbar_saved_successfully), Snackbar.LENGTH_SHORT))
                        .show();
                if (position == 0) {
                    EventBus.getDefault().post(new NewLicenseEvent());
                } else {
                    EventBus.getDefault().post(new UpdateLicenseEvent(license.getCpfNumber()));
                }
            } else {
                ColoredSnackbar.alert(Snackbar.make(form.saveButton,
                        context.getString(R.string.snackbar_save_failed), Snackbar.LENGTH_SHORT)).show();
            }
        }

    });
    form.deleteButton.setVisibility(position == 0 ? View.GONE : View.VISIBLE);
    form.deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(context).setTitle(context.getString(R.string.dialog_title_are_you_sure))
                    .setPositiveButton(context.getString(R.string.dialog_positive),
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    license.delete();
                                    ColoredSnackbar.alert(Snackbar.make(form.deleteButton,
                                            context.getString(R.string.snackbar_removed_successfully),
                                            Snackbar.LENGTH_SHORT)).show();
                                    EventBus.getDefault().post(new DeleteLicenseEvent());
                                }

                            })
                    .setNegativeButton(context.getString(R.string.dialog_negative),
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                }

                            })
                    .show();
        }

    });
    return view;
}

From source file:com.example.liangmutian.linkscrollmsky.MyActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    toolsRe = (RelativeLayout) findViewById(R.id.toolsre);
    backRe = (RelativeLayout) findViewById(R.id.backre);
    overRe = (RelativeLayout) findViewById(R.id.over_re);

    viewPager = (ViewPager) findViewById(R.id.viewpager);

    LayoutInflater lf = getLayoutInflater().from(this);
    view1 = lf.inflate(R.layout.layout1, null);
    view2 = lf.inflate(R.layout.layout2, null);
    viewList = new ArrayList<View>();
    viewList.add(view1);//from   ww w .j  av a2 s. c  o m
    viewList.add(view2);

    listView = (RecyclerView) view1.findViewById(R.id.list);
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < 50; ++i) {
        list.add(" String " + i);
    }
    listView.setAdapter(new StringAdapter(list));
    layoutManager = new LinearLayoutManager(this);
    listView.setLayoutManager(layoutManager);

    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            float alpha = ((float) msg.what) / 100f;
            Log.e("alpha", msg.what + ":" + alpha);
            overRe.setAlpha(alpha);

            if (msg.what == 0) {
                backRe.setVisibility(View.INVISIBLE);
                toolsRe.setVisibility(View.VISIBLE);
            } else {
                backRe.setVisibility(View.VISIBLE);
                toolsRe.setVisibility(View.INVISIBLE);

            }

        }
    };

    pagerAdapter = new PagerAdapter() {

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {

            return arg0 == arg1;
        }

        @Override
        public int getCount() {

            return viewList.size();
        }

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

        }

        @Override
        public int getItemPosition(Object object) {

            return super.getItemPosition(object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(viewList.get(position));

            return viewList.get(position);
        }

    };

    viewPager.setAdapter(pagerAdapter);
    backRe.setPadding(0, 0, 0, DensityUtil.getZhuangtai(this));

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);

    collapsingToolbar.setBackgroundResource(R.drawable.cheese_2);

}

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

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();//  ww  w. ja v  a2s  .  c o m
    TextView valueTV = new TextView(context);
    valueTV.setText(content.optString(TEXT));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    if (Linkify.addLinks(valueTV, Linkify.ALL)) {
        if (!allowInteractions)
            valueTV.setMovementMethod(null);
    }

    frame.addView(valueTV);
}

From source file:com.nightlynexus.viewstatepageradapter.ViewStatePagerAdapter.java

@Override
public final Object instantiateItem(ViewGroup container, int position) {
    if (detached == null) {
        detached = new SparseArray<>();
    }/*  w  w  w .java2s  . co  m*/
    View view = createView(container, position);
    if (view == null) {
        throw new NullPointerException("createView must not return null. (position: " + position + ")");
    }
    SparseArray<Parcelable> viewState = detached.get(position);
    if (viewState != null) {
        view.restoreHierarchyState(viewState);
    }
    container.addView(view);
    attached.put(position, view);
    return view;
}

From source file:au.gov.ga.worldwind.androidremote.client.ui.ItemModelPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    View view = inflater.inflate(R.layout.list_fragment, null);
    ListView listView = (ListView) view.findViewById(android.R.id.list);
    Item item = state.getItem(position);
    listView.setAdapter(state.createListAdapter(inflater, item, flatten));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override//from   w ww .  j  a  v  a2s . c  om
        public void onItemClick(AdapterView<?> parentView, View childView, int listPosition, long id) {
            state.click(position, listPosition, flatten);
        }
    });
    container.addView(view);
    return view;
}