Example usage for android.widget LinearLayout addView

List of usage examples for android.widget LinearLayout addView

Introduction

In this page you can find the example usage for android.widget LinearLayout addView.

Prototype

public void addView(View child) 

Source Link

Document

Adds a child view.

Usage

From source file:com.example.anandchandrasekar.wardrobeadvisor.FilterKindFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_filter_bar, container, false);
    //        TextView filterKindTextView = (TextView) rootView.findViewById(R.id.filterKindTextView);
    LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.hsv_ll);

    //        filterKindTextView.setText(filterKind);
    //        filterKindTextView.setRotation(-90);
    for (int i = 0; i < filtersList.size(); i++) {
        final ItemFilter currFilter = filtersList.get(i);
        final Integer filterId = currFilter.getId();

        View view = FilterView.createNew(getActivity(), currFilter);
        view.setOnClickListener(new View.OnClickListener() {
            @Override//from  w w w .ja va2s. c  om
            public void onClick(View v) {
                if (selectedFiltersList.contains(currFilter)) {
                    removeFilter(currFilter);
                } else {
                    addFilter(currFilter);
                }
            }
        });

        filterViewMap.put(currFilter, view);
        linearLayout.addView(view);
    }

    updateSelectedFilters();

    return rootView;
}

From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    AppCompatActivity activity = mActivityDelegate.getActivity();
    final DrawerLayout drawerLayout = mActivityDelegate.getDrawerLayout();
    activity.getMenuInflater().inflate(R.menu.chatbox_menu, menu);
    MenuItem onlineUsersItem = menu.findItem(R.id.online_users);
    mediaAddItem = menu.findItem(R.id.audio_add);

    /**/*from w w w . ja  v a 2 s  .c o m*/
     * Create badge view for online user item
     */
    ImageButton iconView = new ImageButton(activity, null, R.style.Widget_AppCompat_ActionButton);
    iconView.setImageDrawable(onlineUsersItem.getIcon());
    iconView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawerLayout.isDrawerOpen(DRAWER_GRAVITY_ONLINE_USER)) {
                drawerLayout.closeDrawer(DRAWER_GRAVITY_ONLINE_USER);
            } else {
                drawerLayout.openDrawer(DRAWER_GRAVITY_ONLINE_USER);
            }
        }
    });

    // The badge view requires target view (iconView in this case)
    // to have a ViewGroup parent
    LinearLayout container = new LinearLayout(activity);
    container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    container.addView(iconView);

    Resources res = activity.getResources();
    mOnlineUsersBadgeView = new BadgeView(activity, iconView);
    mOnlineUsersBadgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
    mOnlineUsersBadgeView.setTextSize(TypedValue.COMPLEX_UNIT_SP,
            res.getDimension(R.dimen.badge_view_text_size));
    mOnlineUsersBadgeView.setBadgeMargin(res.getDimensionPixelSize(R.dimen.default_margin));
    onlineUsersItem.setActionView(container);
    mOnlineUsersBadgeView
            .setBadgeBackgroundColor(mActivityDelegate.getActivity().getResources().getColor(R.color.accent));

    return true;
}

From source file:de.devmil.common.ui.color.HistorySelectorView.java

private void makeColorList() {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout colorlist = (LinearLayout) findViewById(R.id.colorlist);

    if (colors == null || colors.length() <= 0) {
        View nocolors = findViewById(R.id.nocolors);
        nocolors.setVisibility(View.VISIBLE);
        colorlist.setVisibility(View.GONE);
        findViewById(R.id.colorlistscroll).setVisibility(View.GONE); //have to remove it's parent container too
        return;//  w  w w  . j a v  a  2s .  c  o  m
    }
    try {
        for (int i = colors.length() - 1; i >= 0; i--) {
            final int color = colors.getInt(i);
            ViewGroup boxgroup = (ViewGroup) inflater.inflate(R.layout.color_historyview_item, colorlist,
                    false);
            TextView box = (TextView) boxgroup.findViewById(R.id.colorbox);
            box.setBackgroundColor(color);
            //box.setText("#"+Integer.toHexString(color));
            colorlist.addView(boxgroup);
            box.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setColor(color);
                    onColorChanged();
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:bizapps.com.healthforusPatient.activity.RegisterActivity.java

public void verifyAccount() {
    final AlertDialog builder = new AlertDialog.Builder(this, R.style.InvitationDialog)
            .setPositiveButton("Done", null).setNegativeButton("Cancel", null).create();

    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    final EditText emailBox = new EditText(this);
    emailBox.setTextColor(getResources().getColor(R.color.icons));
    emailBox.setHintTextColor(getResources().getColor(R.color.icons));
    emailBox.setHint("Email");
    layout.addView(emailBox);

    final EditText codeBox = new EditText(this);
    codeBox.setTextColor(getResources().getColor(R.color.icons));
    codeBox.setHintTextColor(getResources().getColor(R.color.icons));
    codeBox.setHint("Code");
    layout.addView(codeBox);/*from w ww.  jav  a2 s .  c om*/

    builder.setView(layout);

    //      final EditText etNickName = new EditText(this);
    //      etNickName.setTextColor(Color.parseColor("#FFFFFF"));
    //      builder.setView(etNickName);
    builder.setTitle("Verify registration");

    builder.setMessage("Enter emailId and code to activate account");

    builder.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            final Button btnAccept = builder.getButton(AlertDialog.BUTTON_POSITIVE);
            btnAccept.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (emailBox.getText().toString().isEmpty() && codeBox.getText().toString().isEmpty()) {
                        Toast.makeText(getApplicationContext(), "Fields cannot be empty", Toast.LENGTH_SHORT)
                                .show();
                    } else {
                        verifyApi(emailBox.getText().toString(), codeBox.getText().toString());
                        builder.dismiss();
                    }
                }
            });

            final Button btnDecline = builder.getButton(DialogInterface.BUTTON_NEGATIVE);
            btnDecline.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    builder.dismiss();
                }
            });
        }
    });

    builder.show();

}

From source file:fr.shywim.antoinedaniel.ui.MainActivity.java

private void setupAdMob() {
    boolean donated = PrefUtils.hasUserDonated(this);
    LinearLayout adLayout = (LinearLayout) findViewById(R.id.adLayout);
    if (!BuildConfig.DEBUG && Utils.isNetworkAvailable(this) && !donated) {
        mAdView = new AdView(this);
        mAdView.setAdUnitId(getString(R.string.admob_id));
        mAdView.setAdSize(AdSize.SMART_BANNER);
        adLayout.addView(mAdView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);// ww  w  .  j  a  v a2  s.  c o m
        adViewLoaded = true;
    } else {
        removeAdMobLayout();
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.view.survey.SurveyInteractionView.java

@Override
public void doOnCreate(final Activity activity, Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        surveySubmitted = savedInstanceState.getBoolean(KEY_SURVEY_SUBMITTED, false);
    }/*from  ww  w.  jav a 2  s .  c  o m*/

    if (interaction == null || surveySubmitted) {
        activity.finish();
        return;
    }

    activity.setContentView(R.layout.apptentive_survey);

    // Hide branding if needed.
    final View branding = activity.findViewById(R.id.apptentive_branding_view);
    if (branding != null) {
        if (Configuration.load(activity).isHideBranding(activity)) {
            branding.setVisibility(View.GONE);
        }
    }

    TextView title = (TextView) activity.findViewById(R.id.title);
    title.setFocusable(true);
    title.setFocusableInTouchMode(true);
    title.setText(interaction.getName());

    String descriptionText = interaction.getDescription();
    if (descriptionText != null) {
        TextView description = (TextView) activity.findViewById(R.id.description);
        description.setText(descriptionText);
        description.setVisibility(View.VISIBLE);
    }

    final Button send = (Button) activity.findViewById(R.id.send);
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Util.hideSoftKeyboard(activity, view);
            surveySubmitted = true;
            if (interaction.isShowSuccessMessage() && interaction.getSuccessMessage() != null) {
                SurveyThankYouDialog dialog = new SurveyThankYouDialog(activity);
                dialog.setMessage(interaction.getSuccessMessage());
                dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        activity.finish();
                    }
                });
                dialog.show();
            } else {
                activity.finish();
            }

            EngagementModule.engageInternal(activity, interaction, EVENT_SUBMIT, data.toString());
            ApptentiveDatabase.getInstance(activity).addPayload(new SurveyResponse(interaction, surveyState));
            Log.d("Survey Submitted.");
            callListener(true);

            cleanup();
        }
    });

    LinearLayout questions = (LinearLayout) activity.findViewById(R.id.questions);
    questions.removeAllViews();

    // Then render all the questions
    for (final Question question : interaction.getQuestions()) {
        if (question.getType() == Question.QUESTION_TYPE_SINGLELINE) {
            TextSurveyQuestionView textQuestionView = new TextSurveyQuestionView(activity, surveyState,
                    (SinglelineQuestion) question);
            textQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() {
                public void onAnswered() {
                    sendMetricForQuestion(activity, question);
                    send.setEnabled(isSurveyValid());
                }
            });
            questions.addView(textQuestionView);
        } else if (question.getType() == Question.QUESTION_TYPE_MULTICHOICE) {
            MultichoiceSurveyQuestionView multichoiceQuestionView = new MultichoiceSurveyQuestionView(activity,
                    surveyState, (MultichoiceQuestion) question);
            multichoiceQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() {
                public void onAnswered() {
                    sendMetricForQuestion(activity, question);
                    send.setEnabled(isSurveyValid());
                }
            });
            questions.addView(multichoiceQuestionView);
        } else if (question.getType() == Question.QUESTION_TYPE_MULTISELECT) {
            MultiselectSurveyQuestionView multiselectQuestionView = new MultiselectSurveyQuestionView(activity,
                    surveyState, (MultiselectQuestion) question);
            multiselectQuestionView.setOnSurveyQuestionAnsweredListener(new OnSurveyQuestionAnsweredListener() {
                public void onAnswered() {
                    sendMetricForQuestion(activity, question);
                    send.setEnabled(isSurveyValid());
                }
            });
            questions.addView(multiselectQuestionView);
        }
    }

    send.setEnabled(isSurveyValid());

    // Force the top of the survey to be shown first.
    title.requestFocus();
}

From source file:com.eyekabob.ArtistInfo.java

/**
 * This method is called after the last.fm response is received. It will
 * parse the JSON response and put attributes on the Artist object.
 *///from w w w. j ava 2 s  .c o m
protected void handleFutureEventsResponse(JSONObject response) {
    try {
        JSONObject jsonEvents = response.optJSONObject("events");
        if (jsonEvents == null || !jsonEvents.has("event")) {
            futureEventsInfoReturned = true;
            dismissDialogIfReady();
            return;
        }

        JSONArray jsonEventsArray = jsonEvents.getJSONArray("event");
        for (int i = 0; i < jsonEventsArray.length(); i++) {
            Event event = new Event();
            Venue venue = new Venue();
            event.setVenue(venue);

            JSONObject jsonEvent = jsonEventsArray.getJSONObject(i);
            JSONObject jsonVenue = jsonEvent.getJSONObject("venue");
            JSONObject jsonLocation = jsonVenue.getJSONObject("location");
            JSONObject jsonGeo = jsonLocation.optJSONObject("geo:point");

            event.setId(jsonEvent.getString("id"));
            event.setName(jsonEvent.getString("title"));
            event.setDate(EyekabobHelper.LastFM.toReadableDate(jsonEvent.getString("startDate")));
            JSONObject jsonImage = EyekabobHelper.LastFM.getJSONImage("large", jsonEvent.getJSONArray("image"));
            event.addImageURL("large", jsonImage.getString("#text"));

            venue.setName(jsonVenue.getString("name"));
            venue.setCity(jsonLocation.getString("city"));

            if (jsonGeo != null) {
                venue.setLat(jsonGeo.optString("geo:lat"));
                venue.setLon(jsonGeo.getString("geo:long"));
            }

            futureEvents.add(event);
        }
    } catch (JSONException e) {
        Log.e(getClass().getName(), "", e);
    }

    TextView nextConcertDateView = (TextView) findViewById(R.id.infoSubHeaderOne);
    TextView nextConcertLocationView = (TextView) findViewById(R.id.infoSubHeaderTwo);
    Event nextEvent;
    if (futureEvents.size() > 0) {
        nextEvent = futureEvents.get(0);
        // TODO: I18N
        nextConcertDateView.setText("Next Concert: " + nextEvent.getDate() + " @");
        nextConcertLocationView
                .setText(nextEvent.getVenue().getName() + " in " + nextEvent.getVenue().getCity());
        TextView futureEventsHeaderView = (TextView) findViewById(R.id.infoFutureEventsHeader);
        // TODO: I18N
        futureEventsHeaderView.setText("Future Events");
        LinearLayout futureEventsContentView = (LinearLayout) findViewById(R.id.infoFutureEventsContent);
        int i;
        for (i = 0; i < futureEvents.size(); i++) {
            Event event = futureEvents.get(i);
            String futureText = event.getDate() + "\n";
            // TODO: I18N
            futureText += "@ " + event.getVenue().getName() + " in " + event.getVenue().getCity();
            FutureEventView row = new FutureEventView(this);
            row.setTextColor(Color.WHITE);
            row.setPadding(0, 0, 0, 20); // Bottom padding
            row.setText(futureText);
            row.setEvent(event);
            row.setOnClickListener(onClickListener);
            futureEventsContentView.addView(row);
        }
    } else {
        // TODO: I18N
        nextConcertDateView.setText("Next Concert: UNKNOWN");
    }

    futureEventsInfoReturned = true;
    dismissDialogIfReady();
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java

@SuppressWarnings("deprecation")
public View billboardView() {
    LinearLayout billboardLayout = new LinearLayout(context);
    LayoutParams layoutParams = null;/*www  .  j  av a 2  s  . c o  m*/
    if (bgImg != null) {
        billboardLayout.setBackgroundDrawable(new BitmapDrawable(bgImg));
        layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width), UZCoreUtil.dipToPix(height));
    } else {
        billboardLayout.setBackgroundResource(UZResourcesIDFinder.getResDrawableID("mo_bmap_popupmap"));
        layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, UZCoreUtil.dipToPix(height));
    }
    billboardLayout.setLayoutParams(layoutParams);
    billboardLayout.setOrientation(LinearLayout.HORIZONTAL);
    if (getIconAlign().equals("left")) {
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
        billboardLayout.addView(titleLayout());
    } else {
        billboardLayout.addView(titleLayout());
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
    }
    return billboardLayout;
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java

@SuppressWarnings("deprecation")
public View billboardView(ImageView icon) {
    LinearLayout billboardLayout = new LinearLayout(context);
    LayoutParams layoutParams = null;/*from ww w  .  j  av  a 2 s. c o m*/
    if (bgImg != null) {
        billboardLayout.setBackgroundDrawable(new BitmapDrawable(bgImg));
        layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width), UZCoreUtil.dipToPix(height));
    } else {
        billboardLayout.setBackgroundResource(UZResourcesIDFinder.getResDrawableID("mo_bmap_popupmap"));
        layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, UZCoreUtil.dipToPix(height));
    }
    billboardLayout.setLayoutParams(layoutParams);
    billboardLayout.setOrientation(LinearLayout.HORIZONTAL);
    if (getIconAlign().equals("left")) {
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon);
        billboardLayout.addView(titleLayout());
    } else {
        billboardLayout.addView(titleLayout());
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
    }
    return billboardLayout;
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java

private LinearLayout titleLayout() {
    LinearLayout titleLayout = new LinearLayout(context);
    LayoutParams layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width - iconSize - 30),
            UZCoreUtil.dipToPix(height));
    layoutParams.setMargins(UZCoreUtil.dipToPix(10), 0, UZCoreUtil.dipToPix(10), 0);
    titleLayout.setLayoutParams(layoutParams);
    titleLayout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout titleLayout2 = new LinearLayout(context);
    LayoutParams layoutParams2 = new LayoutParams(UZCoreUtil.dipToPix(width - iconSize - 30),
            UZCoreUtil.dipToPix(height - 10));
    titleLayout2.setGravity(Gravity.CENTER_VERTICAL);
    titleLayout2.setOrientation(LinearLayout.VERTICAL);
    titleLayout2.setLayoutParams(layoutParams2);
    titleLayout.addView(titleLayout2);
    titleLayout2.addView(title());/*ww w .j  a  v  a 2s  .co  m*/
    titleLayout2.addView(subTitle());
    return titleLayout;
}