Example usage for android.widget LinearLayout removeAllViews

List of usage examples for android.widget LinearLayout removeAllViews

Introduction

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

Prototype

public void removeAllViews() 

Source Link

Document

Call this method to remove all child views from the ViewGroup.

Usage

From source file:Main.java

public static void addStars(int cre, LinearLayout container, Activity activity, int drawableResId) {
    container.removeAllViews();
    int num = (int) Math.round(cre * 1.0 / 10);
    for (int i = 0; i < num; i++) {
        container.addView(newStar(activity, drawableResId));
    }//from  w w  w. j  av a2  s .  co  m
}

From source file:com.metinkale.prayerapp.vakit.WidgetService.java

private static void extractColors() {
    if (COLOR_1ST != null) {
        return;//from www.  j av a  2 s. c  o m
    }

    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(App.getContext());
        mBuilder.setContentTitle(COLOR_SEARCH_1ST).setContentText(COLOR_SEARCH_2ND);
        Notification ntf = mBuilder.build();
        LinearLayout group = new LinearLayout(App.getContext());
        ViewGroup event = (ViewGroup) ntf.contentView.apply(App.getContext(), group);
        recurseGroup(event);
        group.removeAllViews();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (COLOR_1ST == null) {
        COLOR_1ST = Color.BLACK;
    }
    if (COLOR_2ND == null) {
        COLOR_2ND = Color.DKGRAY;
    }
}

From source file:dynamite.zafroshops.app.fragment.ZopItemFragment.java

public static void setOpeningsList(ArrayList<MobileOpeningHourData> data, LinearLayout listContainer,
        LayoutInflater inflater, TextView label) {
    // set opening hours
    if (data != null && data.size() > 0 && listContainer != null) {
        listContainer.removeAllViews();
        label.setVisibility(View.VISIBLE);

        for (MobileOpeningHourData mohd : data) {
            View listItem = inflater.inflate(R.layout.opening_hour_item, null);
            TextView dayTxt = ((TextView) listItem.findViewById(R.id.openingHoursDay));
            TextView hourTxT = ((TextView) listItem.findViewById(R.id.openingHoursHour));

            try {
                dayTxt.setText(R.string.class.getField("day" + mohd.Day).getInt(null));
            } catch (IllegalAccessException ignored) {

            } catch (NoSuchFieldException e) {
                dayTxt.setText("");
            }//w ww.j a  va 2  s  . c o m

            String hour = "";
            for (MobileOpeningHour moh : mohd.Hours) {
                hour += ((hour.length() > 0) ? ", " : "") + moh.toString();
            }
            hourTxT.setText(hour);

            listContainer.addView(listItem);
        }
    } else {
        if (listContainer != null) {
            listContainer.removeAllViews();
        }
        label.setVisibility(View.INVISIBLE);
    }
}

From source file:syncthing.android.ui.sessionsettings.EditDevicePresenter.java

@BindingAdapter("addShareFolders")
public static void addSharedFolders(LinearLayout shareFoldersContainer, EditDevicePresenter presenter) {
    if (presenter == null)
        return;/*from w  w  w.  j  a  v a2  s  . c  o  m*/
    shareFoldersContainer.removeAllViews();
    for (Map.Entry<String, Boolean> e : presenter.sharedFolders.entrySet()) {
        final String id = e.getKey();
        CheckBox checkBox = new CheckBox(shareFoldersContainer.getContext());
        checkBox.setText(id);
        checkBox.setChecked(e.getValue());
        shareFoldersContainer.addView(checkBox);
        presenter.bindingSubscriptions().add(RxCompoundButton.checkedChanges(checkBox).subscribe(checked -> {
            presenter.setFolderShared(id, checked);
        }));
    }
}

From source file:net.pocketmine.server.HomeActivity.java

public static void updatePlayerList(final String[] nPlayers) {
    players = nPlayers;//from  w  w w. j a  va  2  s  .com

    if (ha != null && inflater != null) {
        ha.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                LinearLayout layout = (LinearLayout) ha.findViewById(R.id.players);
                layout.removeAllViews();

                if (players != null && players.length > 0) {
                    for (final String player : players) {
                        View v = inflater.inflate(R.layout.player, layout, false);
                        TextView playerName = (TextView) v.findViewById(R.id.player_name);
                        playerName.setText(player);
                        final Button kickBtn = (Button) v.findViewById(R.id.player_kick);
                        kickBtn.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View arg0) {
                                LinearLayout ll = new LinearLayout(kickBtn.getContext());
                                final EditText input = new EditText(kickBtn.getContext());
                                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                layoutParams.setMargins(dip2px(8), 0, dip2px(8), 0);
                                input.setLayoutParams(layoutParams);
                                ll.addView(input);
                                new AlertDialog.Builder(kickBtn.getContext()).setTitle(R.string.player_kick)
                                        .setMessage(R.string.kick_reason).setView(ll)
                                        .setPositiveButton(R.string.player_kick,
                                                new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        ServerUtils.executeCMD("kick " + player + " "
                                                                + input.getText().toString());
                                                    }
                                                })
                                        .setNegativeButton(android.R.string.cancel, null).show();
                            }
                        });
                        final Button banBtn = (Button) v.findViewById(R.id.player_ban);
                        banBtn.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View arg0) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(banBtn.getContext());
                                builder.setTitle(R.string.ban_player_title);
                                builder.setItems(ha.getResources().getStringArray(R.array.ban_player_modes),
                                        new DialogInterface.OnClickListener() {

                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                if (which == 0) {
                                                    ServerUtils.executeCMD("ban " + player);
                                                } else if (which == 1) {
                                                    ServerUtils.executeCMD("ban-ip " + player);
                                                }
                                            }
                                        });
                                builder.show();
                            }
                        });
                        layout.addView(v);
                    }
                }
            }
        });
    }
}

From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified {@link Author}s./*from   www  .j  av a 2 s  .  c o m*/
 *
 * @param container {@link LinearLayout} that will contain the authors.
 * @param authors the {@link Author}s to be placed in the container.
 */
@BindingAdapter({ "bind:authors" })
public static void loadAuthorViews(LinearLayout container, List<Author> authors) {
    container.removeAllViews();
    if (authors == null || authors.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Author author : authors) {
        AuthorListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_author, container,
                false);
        AuthorListItemViewModel itemViewModel = new AuthorListItemViewModel();
        itemViewModel.setAuthor(author);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java

/**
 * Removes all views from the {@link LinearLayout} and adds new ones for
 * the specified instances of {@link Category}.
 *
 * @param container {@link LinearLayout} that will contain the categories.
 * @param categories the instances of {@link Category} to be placed in the
 *                   container./*from w  w  w  . j  av a 2 s  .c om*/
 */
@BindingAdapter({ "bind:categories" })
public static void loadCategoryViews(LinearLayout container, List<Category> categories) {
    container.removeAllViews();
    if (categories == null || categories.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Category category : categories) {
        CategoryListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_category,
                container, false);
        CategoryListItemViewModel itemViewModel = new CategoryListItemViewModel();
        itemViewModel.setCategory(category);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

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 Review}s.//  w ww  . ja  va 2s . c o  m
 *
 * @param container {@link LinearLayout} that will contain the reviews.
 * @param reviews the {@link Review}s to be placed in the container.
 */
@BindingAdapter({ "bind:reviews" })
public static void loadReviewViews(LinearLayout container, List<Review> reviews) {
    container.removeAllViews();
    if (reviews == null || reviews.isEmpty()) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) container.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (Review review : reviews) {
        MovieReviewListItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.list_item_movie_review,
                container, false);
        MovieReviewListItemViewModel itemViewModel = new MovieReviewListItemViewModel();
        itemViewModel.setReview(review);
        binding.setViewModel(itemViewModel);
        container.addView(binding.getRoot());
    }
}

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./* ww w.java2s. 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:syncthing.android.ui.sessionsettings.EditFolderPresenter.java

@BindingAdapter("addShareDevices")
public static void addShareDevices(LinearLayout shareDevicesContainer, EditFolderPresenter presenter) {
    if (presenter == null)
        return;//from w  ww .jav a  2  s .c  o m
    shareDevicesContainer.removeAllViews();
    for (Map.Entry<String, Boolean> e : presenter.sharedDevices.entrySet()) {
        final String id = e.getKey();
        CheckBox checkBox = new CheckBox(shareDevicesContainer.getContext());
        DeviceConfig device = presenter.controller.getDevice(id);
        if (device == null) {
            device = new DeviceConfig();
            device.deviceID = id;
        }
        checkBox.setText(SyncthingUtils.getDisplayName(device));
        checkBox.setChecked(e.getValue());
        shareDevicesContainer.addView(checkBox);
        presenter.bindingSubscriptions().add(RxCompoundButton.checkedChanges(checkBox).subscribe(b -> {
            presenter.setDeviceShared(id, b);
        }));
    }
}