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:mx.com.adolfogarcia.popularmovies.model.view.MovieDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified {@link Trailer}s.//from w w  w.  ja va 2 s.  c  o  m
 *
 * @param container {@link LinearLayout} that will contain the trailers.
 * @param trailers the {@link Trailer}s to be placed in the container.
 */
@BindingAdapter({ "bind:trailers" })
public static void loadTrailerViews(LinearLayout container, List<Trailer> trailers) {
    container.removeAllViews();
    if (trailers == null || trailers.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Trailer trailer : trailers) {
        MovieTrailerListItemBinding binding = DataBindingUtil.inflate(inflater,
                R.layout.list_item_movie_trailer, container, false);
        MovieTrailerListItemViewModel itemViewModel = new MovieTrailerListItemViewModel();
        itemViewModel.setTrailer(trailer);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateFirstForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_full_name_title)));

    EditText nameEditText = createEditText(mContext.getString(R.string.account_create_full_name_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_NEXT, false, FULL_NAME_KEY);

    if (mFormData.get(FULL_NAME_KEY) != null) {
        nameEditText.setText(mFormData.get(FULL_NAME_KEY));
    }/*from  www.  j  ava  2 s .  co m*/

    formLayout.addView(nameEditText);
    formLayout.addView(createErrorView(FULL_NAME_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_email_title)));

    EditText emailEditText = createEditText(mContext.getString(R.string.account_create_email_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_NEXT, true, EMAIL_KEY);

    if (mFormData.get(EMAIL_KEY) != null) {
        emailEditText.setText(mFormData.get(EMAIL_KEY));
    }

    formLayout.addView(emailEditText);
    formLayout.addView(createErrorView(EMAIL_KEY));
}

From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    Activity activity = getActivity();//from   www . jav  a2  s. co  m
    switch (item.getItemId()) {
    case R.id.action_refresh:
        urls = new ArrayList<String>();
        imageAdapter.notifyDataSetChanged();
        getImages();
        return true;
    case R.id.action_new:
        final EditText newTitle = new EditText(activity);
        newTitle.setSingleLine();
        newTitle.setHint(R.string.hint_album_title);
        final EditText newDescription = new EditText(activity);
        newDescription.setHint(R.string.body_hint_description);
        LinearLayout linearLayout = new LinearLayout(activity);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(newTitle);
        linearLayout.addView(newDescription);
        new AlertDialog.Builder(activity).setTitle(R.string.dialog_new_album_title).setView(linearLayout)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        NewAlbumAsync messagingAsync = new NewAlbumAsync(newTitle.getText().toString(),
                                newDescription.getText().toString(),
                                ((ImgurHoloActivity) getActivity()).getApiCall(), null, null);
                        messagingAsync.execute();
                    }
                }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing.
                    }
                }).show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.coinblesk.client.ui.authview.AuthenticationDialog.java

@Override
@NonNull//from  w ww.j a  v a 2  s  . c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    address = getArguments().getString(ARG_ADDRESS);
    amount = Coin.valueOf(getArguments().getLong(ARG_AMOUNT));

    final String paymentReq = getArguments().getString(ARG_PAYMENT_REQUEST);
    final boolean isPayerMode = getArguments().getBoolean(ARG_IS_PAYER_MODE);

    authView = getActivity().getLayoutInflater().inflate(R.layout.fragment_authview_dialog, null);

    final TextView addressTextView = (TextView) authView.findViewById(R.id.authview_address_content);
    addressTextView.setText(address);

    final LinearLayout authviewContainer = (LinearLayout) authView.findViewById(R.id.authview_container);
    authviewContainer.addView(new AuthenticationView(getContext(), paymentReq.getBytes()));

    final LinearLayout feeContainer = (LinearLayout) authView.findViewById(R.id.authview_fee_container);
    feeContainer.setVisibility(isPayerMode ? View.VISIBLE : View.GONE);

    final Button cancelButton = (Button) authView.findViewById(R.id.authview_button_cancel);
    //cancelButton.setEnabled(false);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.authViewNegativeResponse();
            }
            dismiss();
        }
    });

    final Switch cancelSwitch = (Switch) authView.findViewById(R.id.authview_switch_cancel);
    cancelSwitch.setVisibility(View.GONE);
    /*cancelSwitch.setChecked(false);
    cancelSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        cancelButton.setEnabled(isChecked);
    }
    });*/

    final Button acceptButton = (Button) authView.findViewById(R.id.authview_button_accept);
    if (isPayerMode) {
        acceptButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.authViewPositiveResponse();
                }
                dismiss();
            }
        });
    } else {
        acceptButton.setVisibility(View.GONE);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogAccent);
    builder.setTitle(R.string.authview_title).setView(authView).setCancelable(false);
    /*
    .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (listener != null) {
                listener.authViewNegativeResponse();
            }
        }
    });
    if (isPayerMode) {
        builder.setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (listener != null) {
                    listener.authViewPositiveResponse();
                }
            }
        });
    }
    */

    return builder.create();
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateSecondForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title)));
    EditText passwordEditText = createEditText(mContext.getString(R.string.account_create_password_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY);
    passwordEditText.setTransformationMethod(new PasswordTransformationMethod());

    formLayout.addView(passwordEditText);
    formLayout.addView(createErrorView(PASSWORD_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title)));
    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);/*from   w  ww.j  a  va  2s. c  o  m*/
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mContext, R.array.sexes_array,
            android.R.layout.simple_spinner_item);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt));
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(GENDER_KEY, adapter.getItem(pos).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    if (mFormData.get(GENDER_KEY) != null) {
        spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY)));
    }

    formLayout.addView(spinner);

}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateThirdForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title)));
    EditText cityEditText = createEditText(mContext.getString(R.string.account_create_city_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, CITY_KEY);

    if (mFormData.get(CITY_KEY) != null) {
        cityEditText.setText(mFormData.get(CITY_KEY));
    }//from   w  w w  .j ava 2 s  . c o  m

    formLayout.addView(cityEditText);
    formLayout.addView(createErrorView(CITY_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title)));

    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item, Countries.COUNTRIES);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt));
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    if (mFormData.get(COUNTRY_KEY) != null) {
        List<String> array = Arrays.asList(Countries.COUNTRY_CODES);
        spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY)));
    }

    formLayout.addView(spinner);
}

From source file:com.javielinux.dialogs.CreateDefaultColumnsUserDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    userId = getArguments().getLong("user_id");

    userEntity = new Entity("users", userId);

    CharSequence[] choices = new CharSequence[3];
    choices[0] = getString(R.string.timeline);
    choices[1] = getString(R.string.mentions);
    choices[2] = getString(R.string.direct_messages);

    final boolean[] isChoices = new boolean[] { true, true, true };

    LinearLayout llTitle = new LinearLayout(getActivity());
    llTitle.setOrientation(LinearLayout.VERTICAL);
    final CheckBox boxInvite = new CheckBox(getActivity());
    boxInvite.setText(R.string.follow_tweettopics);
    boxInvite.setChecked(true);//  w  ww . ja  va2  s . c om
    llTitle.addView(boxInvite);
    TextView txtTitle = new TextView(getActivity());
    txtTitle.setText(R.string.create_columns);
    txtTitle.setTextSize(25);
    llTitle.addView(txtTitle);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setCustomTitle(llTitle);
    builder.setMultiChoiceItems(choices, isChoices, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            isChoices[whichButton] = isChecked;
        }
    });
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // choices
            int count = DataFramework.getInstance().getEntityListCount("columns", "") + 1;
            if (isChoices[0]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_TIMELINE);
                Entity timeline = new Entity("columns");
                timeline.setValue("description", type.getString("description"));
                timeline.setValue("type_id", type);
                timeline.setValue("position", count);
                timeline.setValue("user_id", userEntity.getId());
                timeline.save();
                count++;
            }
            if (isChoices[1]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_MENTIONS);
                Entity mentions = new Entity("columns");
                mentions.setValue("description", type.getString("description"));
                mentions.setValue("type_id", type);
                mentions.setValue("position", count);
                mentions.setValue("user_id", userEntity.getId());
                mentions.save();
                count++;
            }
            if (isChoices[2]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_DIRECT_MESSAGES);
                Entity dms = new Entity("columns");
                dms.setValue("description", type.getString("description"));
                dms.setValue("type_id", type);
                dms.setValue("position", count);
                dms.setValue("user_id", userEntity.getId());
                dms.save();
            }

            ((TweetTopicsActivity) getActivity()).refreshColumns();

            // create friend
            if (boxInvite.isChecked()) {
                Utils.showMessage(getActivity(), getActivity().getString(R.string.thanks));
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ConnectionManager.getInstance().getTwitter(userEntity.getId())
                                    .createFriendship("tweettopics_app");
                        } catch (TwitterException e1) {
                            e1.printStackTrace();
                        } catch (IllegalArgumentException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }

    });

    return builder.create();

}

From source file:com.example.team04adventure.Controller.OnlineStoryList.java

/**
 * Shows the help information for this fragment.
 */// w ww  .  j a v  a2 s  . c o  m
private void help() {
    String helpText = "All stories are displayed here. Press a story to read it. Online stories contains all"
            + "the stories on the server. My stories contains all the stories written by you."
            + "Cached stories contains all the stories downloaded on your phone that aren't written by you. "
            + "The 'I'm Feeling Lucky!' button chooses a random story for you from the existing online stories."
            + "The 'Add Story' button lets you create a new story, and new stories can only be published by creating a"
            + "new story from here. The 'Sync' button locally mirrors the cached stories with the online stories so that"
            + "the cached stories are updated.";
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    LinearLayout lila1 = new LinearLayout(this);
    lila1.setOrientation(1);

    final TextView helpTextView = new TextView(this);
    helpTextView.setText(helpText);
    lila1.addView(helpTextView);
    adb.setView(lila1);
    adb.setTitle("Help");

    adb.show();
}

From source file:com.weizoo.game.go.HappyGo.HappyGo.java

private void initAd() {
    try {/*ww w .  j  a v  a 2  s .c o  m*/
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        // Create the adView.
        adView = new AdView(this, AdSize.SMART_BANNER, "a152c6a39379a40");

        // Add the adView to it.
        layout.addView(adView);

        // Initiate a generic request.
        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice("355296050198170");
        // Load the adView with the ad request.
        adView.loadAd(adRequest);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.fullmeadalchemist.mustwatch.ui.recipe.detail.RecipeDetailFragment.java

private void updateRecipeIngredientUiInfo() {
    if (viewModel.recipe.ingredients != null) {
        // FIXME: this is not performant and looks ghetto.
        Timber.d("Found %s BatchIngredients for this Recipe; adding them to the ingredientsList",
                viewModel.recipe.ingredients.size());
        LinearLayout ingredientsList = getActivity().findViewById(R.id.ingredients_list);
        ingredientsList.removeAllViews();
        for (BatchIngredient ingredient : viewModel.recipe.ingredients) {
            BatchIngredientView ingredientText = new BatchIngredientView(getActivity());
            ingredientText.setBatchIngredient(ingredient);
            ingredientsList.addView(ingredientText);
        }//  www  . j  av a  2  s .c o  m
    } else {
        Timber.d("No Ingredients found for this Recipe.");
    }
}