Example usage for android.view ViewGroup removeAllViews

List of usage examples for android.view ViewGroup removeAllViews

Introduction

In this page you can find the example usage for android.view ViewGroup removeAllViews.

Prototype

public void removeAllViews() 

Source Link

Document

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

Usage

From source file:org.rssin.android.NavigationDrawerManageFeedsFragment.java

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

    final Bundle args = getArguments();
    rootView = inflater.inflate(R.layout.fragment_feeds, container, false);
    final Context context = rootView.getContext();

    feedsView = (ListView) rootView.findViewById(R.id.feeds_list);

    try {/*ww w  .  j  ava2  s .  com*/
        feedsList = FeedsList.getInstance(context);
    } catch (IOException e) {
        Frontend.error(context, R.string.error_load_feeds, e);
    }

    feedAdapter = new FeedAdapter(context, R.layout.item_feed, feedsList.getFeeds());
    feedsView.setAdapter(feedAdapter);

    feedsView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Feed feed = feedAdapter.getItem(position);
            DefaultStorageProvider.getInstance(context).removeFeed(feed.getStorageKey());
            feedsList.getFeeds().remove(feed);
            feedAdapter.notifyDataSetChanged();
            return true;
        }
    });

    return rootView;
}

From source file:com.draekko.traypreferencesapp.SampleAppPreferences.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    LinearLayout content = (LinearLayout) root.getChildAt(0);
    LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar, null);

    root.removeAllViews();
    toolbarContainer.addView(content);/*from   w w w.j  av a2s.c o  m*/
    root.addView(toolbarContainer);

    mToolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar);
    mToolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.white));
    mToolbar.setSubtitleTextColor(ContextCompat.getColor(this, R.color.white));
    mToolbar.setNavigationIcon(R.drawable.ic_back_material_light);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java

/**
 * Recreates the content/*from www  .j  a v  a 2 s.co m*/
 */
public void updateFragment() {
    if (getView() == null)
        return;

    ViewGroup vg = getContentView();

    vg.removeAllViews();

    createRootView(getActivity().getLayoutInflater(), vg);
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public void setFragmentLoading() {
    if (getView() == null)
        return;/*w w  w .j av a 2  s  . c o m*/

    ViewGroup vg = getContentView();
    vg.removeAllViews();

    vg.addView(createLoadingView());
}

From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java

public void updateFragment() {
    if (getView() == null)
        return;/*  w w  w .ja  v a2 s.c  o m*/

    ViewGroup vg = getContentView();

    vg.removeAllViews();

    createRootView(getActivity().getLayoutInflater(), vg);
}

From source file:com.github.pennyfive.sqlitestudio.ui.PackagesFragment.java

@Override
public void onLoadFinished(Loader<Result> resultLoader, Result result) {
    TextView databaseCountHeader = (TextView) View.inflate(getActivity(), R.layout.header_text, null);
    databaseCountHeader.setText(getResources().getQuantityString(R.plurals.databases_header_num_databases,
            result.getTotalNumDatabases(), result.getTotalNumDatabases()));
    listView.addHeaderView(databaseCountHeader, null, false);

    listView.setAdapter(new BinderAdapter<ScannedPackage>(getActivity(), result.getScannedPackages()) {
        @Override//from w ww  . ja v  a 2 s.  c  o m
        protected View newView(LayoutInflater inflater, ViewGroup parent) {
            return inflater.inflate(R.layout.item_package, parent, false);
        }

        @Override
        protected void bindView(View view, final ScannedPackage item, int position) {
            Drawable applicationIcon = getApplicationIcon(item.getPackageName());
            ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(applicationIcon);

            String applicationName = getApplicationName(item.getPackageName());
            ((TextView) view.findViewById(R.id.application_name)).setText(applicationName);

            ((TextView) view.findViewById(R.id.package_name)).setText(item.getPackageName());

            ((TextView) view.findViewById(R.id.num_databases)).setText(String.valueOf(item.getNumDatabases()));

            final ViewGroup databaseLayout = (ViewGroup) view.findViewById(R.id.database_layout);
            databaseLayout.removeAllViews();

            final LayoutInflater inflater = LayoutInflater.from(getActivity());

            final int databasesCount = item.getNumDatabases();
            int initialItemCount = databasesCount > NUM_DATABASES_WHEN_COLLAPSED + 1
                    ? NUM_DATABASES_WHEN_COLLAPSED
                    : databasesCount;
            for (int i = 0; i < initialItemCount; i++) {
                databaseLayout
                        .addView(inflateDatabaseItem(inflater, databaseLayout, item.getDatabasePaths().get(i)));
            }

            if (databasesCount > initialItemCount) {
                View showAllFooter = inflater.inflate(R.layout.item_package_show_all_extra, null);
                databaseLayout.addView(showAllFooter);
                showAllFooter.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        databaseLayout.removeView(v);
                        for (int i = databaseLayout.getChildCount(); i < databasesCount; i++) {
                            databaseLayout.addView(inflateDatabaseItem(inflater, databaseLayout,
                                    item.getDatabasePaths().get(i)));
                        }
                    }
                });
            }
        }

        private View inflateDatabaseItem(LayoutInflater inflater, ViewGroup parent, final String databasePath) {
            View databaseItem = inflater.inflate(R.layout.item_package_database_extra, parent, false);
            String databaseFileName = databasePath.substring(databasePath.lastIndexOf('/') + 1,
                    databasePath.length());
            ((TextView) databaseItem.findViewById(R.id.text)).setText(databaseFileName);
            databaseItem.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    onDatabaseSelected(databasePath);
                }
            });
            return databaseItem;
        }
    });
}

From source file:com.example.demo_highlights.slidingmenu.fragment.ViewPageFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View mView = inflater.inflate(R.layout.view_pager, null);

    ViewGroup p = (ViewGroup) mView.getParent();

    if (p != null) {
        p.removeAllViews();
    }//ww  w.  j a v  a 2s .  co m

    showLeft = (Button) mView.findViewById(R.id.showLeft);
    showRight = (Button) mView.findViewById(R.id.showRight);
    mPager = (ViewPager) mView.findViewById(R.id.pager);
    mTabSwitcher = (TabSwitcher) mView.findViewById(R.id.switcher);

    PageFragment1 page1 = new PageFragment1();
    PageFragment2 page2 = new PageFragment2();
    PageFragment2 page3 = new PageFragment2();
    PageFragment2 page4 = new PageFragment2();
    pagerItemList.add(page1);
    pagerItemList.add(page2);
    pagerItemList.add(page3);
    pagerItemList.add(page4);
    mAdapter = new MyAdapter(getFragmentManager());
    mPager.setAdapter(mAdapter);
    mPager.setOffscreenPageLimit(4);
    mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {

            if (myPageChangeListener != null) {
                myPageChangeListener.onPageSelected(position);
                mTabSwitcher.setPosition(position);
                //               mTabSwitcher.setFocusable(true);
                //               mTabSwitcher.clearAnimation();
                Log.d("zhengpanyong", "onPageSelected:" + position);
            }

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

            Log.d("zhengpanyong", "int arg0, float arg1, int arg2:" + arg0 + "," + arg1 + "," + arg2);

            //               imageView.startAnimation(animation);  

        }

        @Override
        public void onPageScrollStateChanged(int position) {

            //            mTabSwitcher.setPosition(position);

        }
    });
    mTabSwitcher.setPager(mPager);
    return mView;
}

From source file:com.sweetiepiggy.littlepro.SubmitQuizFragment.java

private boolean update(Map<Long, String> questionIdAndCorrectAnswers) {
    View view = getView();//from  w  w  w  .j  av a 2s. co  m
    if (view == null) {
        boolean allowUnlock = false;
        return allowUnlock;
    }

    ViewGroup questionsLayout = (ViewGroup) view.findViewById(R.id.questions_layout);
    mAnswerViews.clear();
    questionsLayout.removeAllViews();

    int correctPoints = 0;
    int totalPoints = 0;

    for (Pair<Question, String> questionAndAnswer : mSubmitQuizListener.getQuestionAndAnswers()) {
        Question question = questionAndAnswer.first;
        String answer = questionAndAnswer.second;
        String correctAnswer = null;
        int points = question.getPoints();
        totalPoints += points;
        if (questionIdAndCorrectAnswers != null) {
            correctAnswer = questionIdAndCorrectAnswers.get(question.getId());
        }
        TextView answerView = new TextView(getActivity());
        if (mSubmitted) {
            if (answer.equals(correctAnswer)) {
                answerView.setText(answer + ": Correct");
                correctPoints += points;
            } else {
                answerView.setText(answer + ": Wrong");
            }
        } else {
            answerView.setText(answer);
        }
        mAnswerViews.add(answerView);
        questionsLayout.addView(answerView);
        mQuestionIdAndAnswers.put(question.getId(), answer);
    }

    if (mSubmitted) {
        view.findViewById(R.id.submit_button).setVisibility(View.GONE);
    }

    double percentCorrect = (totalPoints == 0) ? 0. : (100. * correctPoints) / totalPoints;
    boolean allowUnlock = percentCorrect >= 75.;
    return allowUnlock;
}

From source file:com.android_mobile.core.ui.comp.banner.LoopViewPager.java

public void setDotParent(ViewGroup layout) {
    this.dotParent = layout;
    layout.removeAllViews();
    addDot();
}

From source file:com.github.chilinh.android.form.Form.java

private void makeFormView(ViewGroup containerView) {
    containerView.removeAllViews();

    for (SectionElement section : getSections()) {
        section.setModel(mModel);//w w w.ja  va  2 s  .c o  m
        section.makeView(containerView);
    }
}