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:org.mklab.mikity.android.SampleSelectionFragment.java

/**
 * ????????//from   ww  w  .  j  av  a2 s  .  com
 */
void createSourceComponent(View mainView) {
    final List<GroupModel> rootGroups = this.canvasFragment.root.getScene(0).getGroups();
    final Set<String> sourceIds = getAllSourceIds(rootGroups);

    final LinearLayout sources = (LinearLayout) mainView.findViewById(R.id.layout_sample_sources);
    sources.removeAllViews();

    this.sourceSelectButtons.clear();
    this.sourceFileNameViews.clear();

    for (final String id : sourceIds) {
        final LinearLayout source = (LinearLayout) SampleSelectionFragment.this.mainActivity.getLayoutInflater()
                .inflate(R.layout.sample_source, null);
        sources.addView(source);

        final Button selectButton = (Button) source.findViewById(R.id.sampleSourceSelectButton);
        selectButton.setText(getString(R.string.source) + "(" + id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
        this.sourceSelectButtons.add(selectButton);

        selectButton.setOnClickListener(new OnClickListener() {

            /**
             * {@inheritDoc}
             */
            public void onClick(View view) {
                final FragmentManager manager = SampleSelectionFragment.this.mainActivity
                        .getSupportFragmentManager();
                final FragmentTransaction transaction = manager.beginTransaction();
                transaction.addToBackStack(null);

                if (SampleSelectionFragment.this.sourceViewFragment != null) {
                    transaction.remove(SampleSelectionFragment.this.sourceViewFragment);
                    SampleSelectionFragment.this.sourceViewFragment = null;
                }

                SampleSelectionFragment.this.sourceViewFragment = new AssetsListViewFragment();
                final Bundle arguments = new Bundle();
                arguments.putString("sourceId", id); //$NON-NLS-1$
                arguments.putBoolean("isModelData", false); //$NON-NLS-1$
                SampleSelectionFragment.this.sourceViewFragment.setArguments(arguments);

                transaction.add(R.id.fragment_navigation_drawer,
                        SampleSelectionFragment.this.sourceViewFragment);
                transaction.commit();
            }
        });

        final TextView sourceFileNameView = (TextView) source.findViewById(R.id.sampleSourceFileNameView);
        if (this.sourceFileNames.containsKey(id)) {
            sourceFileNameView.setText(this.sourceFileNames.get(id));
        }
        this.sourceFileNameViews.put(id, sourceFileNameView);

    }
}

From source file:com.mobicage.rogerthat.FriendDetailOrInviteActivity.java

private void updateView() {
    final ImageView image = (ImageView) findViewById(R.id.friend_avatar);

    if (mFriend == null) {
        image.setVisibility(View.INVISIBLE);
        return;/* ww w  .j ava 2  s  .c  o  m*/
    }
    image.setVisibility(View.VISIBLE);
    final TextView nameView = (TextView) findViewById(R.id.friend_name);

    if (mFriend.avatar == null) {
        image.setImageBitmap(mFriendsPlugin.getMissingFriendAvatarBitmap());
    } else {
        final Bitmap avatarBitmap = BitmapFactory.decodeByteArray(mFriend.avatar, 0, mFriend.avatar.length);
        image.setImageBitmap(ImageHelper.getRoundedCornerAvatar(avatarBitmap));
    }

    setTitle(mFriend.getDisplayName());
    nameView.setText(mFriend.getDisplayName());
    nameView.setTextColor(ContextCompat.getColor(this, android.R.color.primary_text_light));

    final LinearLayout profileDataContainer = (LinearLayout) findViewById(R.id.profile_data);
    if (AppConstants.PROFILE_DATA_FIELDS.length > 0) {
        profileDataContainer.removeAllViews();
        profileDataContainer.setVisibility(View.VISIBLE);
        Map<String, String> profileData = mFriend.getProfileDataDict();
        for (String k : AppConstants.PROFILE_DATA_FIELDS) {
            final LinearLayout ll = (LinearLayout) View.inflate(this, R.layout.profile_data_detail, null);
            final TextView tvKey = (TextView) ll.findViewById(R.id.profile_data_detail_key);
            final TextView tvVal = (TextView) ll.findViewById(R.id.profile_data_detail_value);

            String v = profileData == null ? null : profileData.get(k);
            if (v == null) {
                v = getString(R.string.unknown);
            }
            tvKey.setText(k);
            tvKey.setTextColor(LookAndFeelConstants.getPrimaryColor(this));
            tvVal.setText(v);

            profileDataContainer.addView(ll);
        }
    } else {
        profileDataContainer.setVisibility(View.GONE);
    }
}

From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.EditFieldActivity.java

private void recreateEditingUi() {

    IControllerFactory controllerFactory = BasicControllerFactory.getInstance();

    mFieldController = controllerFactory.createControllerForField(mField);

    if (mFieldController == null) {
        // Log.d(AnkiDroidApp.TAG, "Field controller creation failed");
        return;/* ww w . j a  v  a2s  .c om*/
    }

    mFieldController.setField(mField);
    mFieldController.setFieldIndex(mFieldIndex);
    mFieldController.setNote(mNote);
    mFieldController.setEditingActivity(this);

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LinearLayoutInScrollViewFieldEdit);

    linearLayout.removeAllViews();

    mFieldController.createUI(linearLayout);

}

From source file:mobisocial.musubi.webapp.WebAppActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    //this works around a memory leak with the webview that occurs at least on all <= 2.3.7
    LinearLayout web_view_parent = (LinearLayout) findViewById(R.id.db1_root);
    web_view_parent.removeAllViews();
    mDestroyed = true;/*from   w  w  w. j a  va 2 s  .c  o m*/
    mWebView.destroy();
}

From source file:com.ichi2.anki.multimediacard.activity.EditFieldActivity.java

private void recreateEditingUi() {

    IControllerFactory controllerFactory = BasicControllerFactory.getInstance();

    mFieldController = controllerFactory.createControllerForField(mField);

    if (mFieldController == null) {
        Timber.d("Field controller creation failed");
        return;/*w  w w. jav a 2s  . c  om*/
    }

    mFieldController.setField(mField);
    mFieldController.setFieldIndex(mFieldIndex);
    mFieldController.setNote(mNote);
    mFieldController.setEditingActivity(this);

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LinearLayoutInScrollViewFieldEdit);

    linearLayout.removeAllViews();

    mFieldController.createUI(linearLayout);

}

From source file:com.nadmm.airports.wx.AirSigmetFragment.java

protected void showAirSigmetText(Intent intent) {
    if (getActivity() == null) {
        return;//from w w w  .  j  a  v a 2  s. c om
    }

    AirSigmet airSigmet = (AirSigmet) intent.getSerializableExtra(NoaaService.RESULT);

    LinearLayout layout = (LinearLayout) findViewById(R.id.airsigmet_entries_layout);
    if (layout == null) {
        return;
    }

    layout.removeAllViews();

    TextView tv = (TextView) findViewById(R.id.airsigmet_title_msg);
    if (!airSigmet.entries.isEmpty()) {
        tv.setText(String.format("%d AIR/SIGMETs reported within %d NM of %s in" + " last %d hours",
                airSigmet.entries.size(), AIRSIGMET_RADIUS_NM, mStationId, AIRSIGMET_HOURS_BEFORE));
        for (AirSigmetEntry entry : airSigmet.entries) {
            showAirSigmetEntry(layout, entry);
        }
    } else {
        tv.setText(String.format("No AIR/SIGMETs reported within %d NM of %s in" + " last %d hours",
                AIRSIGMET_RADIUS_NM, mStationId, AIRSIGMET_HOURS_BEFORE));
    }

    tv = (TextView) findViewById(R.id.wx_fetch_time);
    tv.setText("Fetched on " + TimeUtils.formatDateTime(getActivity(), airSigmet.fetchTime));
    tv.setVisibility(View.VISIBLE);

    stopRefreshAnimation();
    setFragmentContentShown(true);
}

From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java

private void extractColors(Context context) {
    if (notification_text_color != null)
        return;//from ww w  .  ja va2s. co  m

    try {
        Notification ntf = new Notification();
        ntf.setLatestEventInfo(context, COLOR_SEARCH_RECURSE_TIP, "Utest", null);
        LinearLayout group = new LinearLayout(context);
        ViewGroup event = (ViewGroup) ntf.contentView.apply(context, group);
        recurseGroup(context, event);
        group.removeAllViews();
    } catch (Exception e) {
        notification_text_color = android.R.color.black;
    }
}

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

private void setLayout(LayoutInflater inflater, LinearLayout layout, final FullMobileZop zop,
        RelativeLayout loader) {/*from w  ww .ja  v  a  2  s .c om*/
    LinearLayout item = (LinearLayout) layout.findViewById(R.id.itemZop);

    loader.setVisibility(View.VISIBLE);
    item.setVisibility(View.INVISIBLE);
    if (zop != null && zop.id != null && !zop.id.trim().equals("")) {
        MainActivity activity = (MainActivity) getActivity();
        (activity).setCurrentItem(zop.id, zop);

        LinearLayout list = (LinearLayout) layout.findViewById(R.id.zopOpeningHours);
        ArrayList<MobileOpeningHourData> ohs = zop.getGroupedOpeningHours();

        // set other fields
        ((ImageView) item.findViewById(R.id.zopImg)).setImageResource(R.drawable.nopictureyet);
        ((TextView) item.findViewById(R.id.zopName)).setText(zop.Name);
        ((TextView) item.findViewById(R.id.zopStreet)).setText(zop.Street + " " + zop.StreetNumber);
        ((TextView) item.findViewById(R.id.zopCity)).setText(zop.City);
        ((TextView) item.findViewById(R.id.zopCountry)).setText(zop.CountryName);

        LinearLayout linearLayout = ((LinearLayout) item.findViewById(R.id.zopServiceIcons));

        linearLayout.removeAllViews();
        setView(zop.Type.toString(), zop.Type.getText(), linearLayout, inflater);
        for (Object s : zop.Services) {
            ZopServiceType zopServiceType = ((MobileZopService) s).Service;

            if (!zopServiceType.toString().equals(zop.Type.toString())) {
                setView(zopServiceType.toString(), zopServiceType.getText(), linearLayout, inflater);
            }
        }

        if (zop.Distance > 0) {
            ((TextView) item.findViewById(R.id.locatoin_km)).setText(
                    " (" + String.format("%.0f", zop.Distance) + " " + getString(R.string.far_away) + ")");
        }
        if (zop.PhoneNumber == null || zop.PhoneNumber.trim().equals("")) {
            item.findViewById(R.id.zopPhoneNumberLabel).setVisibility(View.INVISIBLE);
        } else {
            item.findViewById(R.id.zopPhoneNumberLabel).setVisibility(View.VISIBLE);
            ((TextView) item.findViewById(R.id.zopPhoneNumber))
                    .setText(zop.CountryPhoneCode + " " + zop.PhoneNumber);
        }

        if (zop.Details == null || zop.Details.trim().equals("")) {
            item.findViewById(R.id.zopDetailsLabel).setVisibility(View.INVISIBLE);
        } else {
            item.findViewById(R.id.zopDetailsLabel).setVisibility(View.VISIBLE);
            ((TextView) item.findViewById(R.id.zopDetails)).setText(zop.Details);
        }
        // set opening hours
        setOpeningsList(ohs, list, inflater, (TextView) item.findViewById(R.id.zopOpeningHoursLabel));
        loader.setVisibility(View.INVISIBLE);
        item.setVisibility(View.VISIBLE);
    }
}

From source file:org.gots.seed.view.SeedWidgetLong.java

@SuppressWarnings("deprecation")
private void setupView() {

    if (mSeed == null)
        return;//from  w ww . j ava2  s .c  om

    int familyImageRessource = 0;
    if (mSeed.getFamily() != null)
        familyImageRessource = getResources()
                .getIdentifier("org.gots:drawable/family_" + mSeed.getFamily().toLowerCase(), null, null);

    if (familyImageRessource != 0)
        setBackgroundResource(familyImageRessource);
    else {
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.family_unknown));
        } else {
            setBackground(mContext.getResources().getDrawable(R.drawable.family_unknown));
        }
    }

    SeedWidget seedWidget = (SeedWidget) findViewById(R.id.idSeedWidget2);
    seedWidget.setSeed(mSeed);

    TextView seedSpecie = (TextView) findViewById(R.id.IdSeedSpecie);
    seedSpecie.setText(SeedUtil.translateSpecie(mContext, mSeed));
    if (GotsPreferences.DEBUG)
        seedSpecie.setText("(" + mSeed.getSeedId() + ")" + SeedUtil.translateSpecie(mContext, mSeed));

    TextView seedVariety = (TextView) findViewById(R.id.IdSeedVariety);
    seedVariety.setText(mSeed.getVariety());

    PlanningWidget planningSow = (PlanningWidget) findViewById(R.id.IdSeedSowingPlanning);
    planningSow.setAdapter(new PlanningSowAdapter(mSeed));
    //
    PlanningWidget planningHarvest = (PlanningWidget) findViewById(R.id.IdSeedHarvestPlanning);
    planningHarvest.setAdapter(new PlanningHarvestAdapter(mSeed));

    LinearLayout stock = (LinearLayout) findViewById(R.id.idSeedStock);
    stock.removeAllViews();
    for (int i = 0; i < mSeed.getNbSachet(); i++) {
        ImageView seedbag = new ImageView(mContext);
        seedbag.setImageDrawable(mContext.getResources().getDrawable(R.drawable.seed_bag));
        // seedbag.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.bg_planning_sow));

        LayoutParams params = new LinearLayout.LayoutParams(30, 30);
        seedbag.setLayoutParams(params);
        stock.addView(seedbag, i);
    }

    if (mSeed.getLanguage() != null && !"".equals(mSeed.getLanguage())) {
        ImageView flag = (ImageView) findViewById(R.id.IdSeedLanguage);
        int flagRessource = getResources()
                .getIdentifier("org.gots:drawable/" + mSeed.getLanguage().toLowerCase(), null, null);
        flag.setImageResource(flagRessource);
    }

    likeCount = (TextView) findViewById(R.id.textSeedLike);
    like = (ImageView) findViewById(R.id.ImageSeedLike);

    displayLikeStatus(mSeed.getLikeStatus());
    if (mSeed.getUUID() == null)
        like.setVisibility(View.GONE);

    like.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AsyncTask<Void, Void, LikeStatus>() {
                GotsException exception = null;

                @Override
                protected LikeStatus doInBackground(Void... params) {
                    GotsSeedManager manager = GotsSeedManager.getInstance().initIfNew(mContext);
                    try {
                        return manager.like(mSeed, mSeed.getLikeStatus().getUserLikeStatus() == 1);
                    } catch (GotsException e) {
                        exception = e;
                        return null;
                    } catch (Exception e) {
                        Log.e(getClass().getName(), "" + e.getMessage(), e);
                        return null;
                    }
                }

                protected void onPostExecute(LikeStatus result) {
                    if (result == null && exception != null) {
                        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

                        // set title
                        alertDialogBuilder.setTitle(exception.getMessage());
                        alertDialogBuilder.setMessage(exception.getMessageDescription()).setCancelable(false)
                                .setPositiveButton(mContext.getResources().getString(R.string.login_connect),
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int id) {
                                                // Intent loginIntent = new Intent(mContext, LoginDialogFragment.class);
                                                // mContext.startActivity(loginIntent);
                                                LoginDialogFragment dialogFragment = new LoginDialogFragment();
                                                dialogFragment.setStyle(DialogFragment.STYLE_NORMAL,
                                                        R.style.CustomDialog);
                                                dialogFragment.show(((FragmentActivity) mContext)
                                                        .getSupportFragmentManager(), "");
                                            }
                                        })
                                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });

                        AlertDialog alertDialog = alertDialogBuilder.create();

                        alertDialog.show();

                        return;
                    }
                    mSeed.setLikeStatus(result);
                    displayLikeStatus(result);
                    mContext.sendBroadcast(new Intent(BroadCastMessages.SEED_DISPLAYLIST));

                };
            }.execute();

        }
    });
}

From source file:com.cmput301.recipebot.ui.AbstractRecipeActivity.java

/**
 * A method that fills a {@link LinearLayout} with data from a List of data.
 * We don't use {@link android.widget.ListView} since we don't need scrolling, our {@link android.widget.ScrollView} handles
 * that for us.// w ww .j  a  v a2 s  .c  om
 *
 * @param listDirections the layout to fill
 * @param dataset        the data that should be displayed.
 */
protected void fillListLayout(LinearLayout listDirections, List dataset, int type) {
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //Sanitize the view
    listDirections.removeAllViews();

    for (int i = 0; i < dataset.size(); i++) {
        Object data = dataset.get(i);
        CheckBox checkBox = (CheckBox) layoutInflater.inflate(R.layout.checkbox_view, null);
        checkBox.setText(data.toString());
        TaggedItem item = new TaggedItem();
        item.type = type;
        item.data = data;
        checkBox.setTag(item);
        checkBox.setOnCheckedChangeListener(this);
        listDirections.addView(checkBox, i);
    }
}