Example usage for android.view ViewGroup findViewById

List of usage examples for android.view ViewGroup findViewById

Introduction

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

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:android.example.com.animationdemos.LayoutChangesActivity.java

private void addItem() {
    // Instantiate a new "row" view.
    final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example,
            mContainerView, false);//  ww  w  . ja  va2  s.co m
    // Set the text in the new row to a random country.
    ((TextView) newView.findViewById(android.R.id.text1))
            .setText(COUNTRIES[(int) (Math.random() * COUNTRIES.length)]);
    // Set a click listener for the "X" button in the row that will remove the row.
    newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Remove the row from its parent (the container view).
            // Because mContainerView has android:animateLayoutChanges set to true,
            // this removal is automatically animated.
            mContainerView.removeView(newView);
            // If there are no rows remaining, show the empty view.
            if (mContainerView.getChildCount() == 0) {
                findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
            }
        }
    });
    // Because mContainerView has android:animateLayoutChanges set to true,
    // adding this view is automatically animated.
    mContainerView.addView(newView, 0);
}

From source file:cn.jarlen.mediaplayer.sample.fragments.FileListFragment.java

@Nullable
@Override/* ww w  .j a va 2 s.c  o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_file_list, container, false);
    mPathView = (TextView) viewGroup.findViewById(R.id.path_view);
    mFileListView = (ListView) viewGroup.findViewById(R.id.file_list_view);

    mPathView.setVisibility(View.VISIBLE);

    return viewGroup;
}

From source file:com.tdispatch.passenger.core.TDActivity.java

@Override
public void setContentView(int layoutId) {

    if (useContainerWithLockUIOverlay() == true) {
        LayoutInflater inflater = getLayoutInflater();

        ViewGroup activityLayout = (ViewGroup) inflater.inflate(R.layout.tdactivity, null);
        ViewGroup contentContainer = (ViewGroup) activityLayout.findViewById(R.id.tdactivity_content_container);

        inflater.inflate(layoutId, contentContainer);

        super.setContentView(activityLayout);

        doHandleUiLock(0);//  w w w .jav a2  s . co  m
    } else {
        super.setContentView(layoutId);
    }

    // set custom fonts
    setCustomFonts();
}

From source file:com.andrew.apollo.ui.fragments.LyricsFragment.java

/**
 * {@inheritDoc}//from   ww w.  j  av  a 2s  .c  o m
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    // The View for the fragment's UI
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.lyrics_base, null);
    // Initialize the lyrics text view
    mLyrics = (TextView) rootView.findViewById(R.id.audio_player_lyrics);
    // Enable text selection
    if (ApolloUtils.hasHoneycomb()) {
        mLyrics.setTextIsSelectable(true);
    }
    // Initialze the progess bar
    mProgressBar = (ProgressBar) rootView.findViewById(R.id.audio_player_lyrics_progess);
    return rootView;
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert// ww w.  j  a v a2 s .c o m
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}

From source file:com.example.combatcalculator.SpecialRulesActivity.java

private void addItem() {
    // Instantiate a new "row" view.
    final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_special_rules,
            mContainerView, false);//  w  w  w  . ja v a 2 s .c  o m

    // Set the text in the new row to a random country.
    ((TextView) newView.findViewById(android.R.id.text1))
            .setText(COUNTRIES[(int) (Math.random() * COUNTRIES.length)]);

    // Set a click listener for the "X" button in the row that will remove the row.
    newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            // Remove the row from its parent (the container view).
            // Because mContainerView has android:animateLayoutChanges set to true,
            // this removal is automatically animated.
            mContainerView.removeView(newView);

            // If there are no rows remaining, show the empty view.
            if (mContainerView.getChildCount() == 0) {
                findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
            }
        }
    });

    // Because mContainerView has android:animateLayoutChanges set to true,
    // adding this view is automatically animated.
    mContainerView.addView(newView, 0);
}

From source file:com.racoon.ampdroid.views.SelectedPlaylistsView.java

@SuppressLint("InflateParams")
@Override/*  w  w w. j a v a  2 s .  c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    controller = Controller.getInstance();
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.ampache_playlists, null);
    ListView listview = (ListView) root.findViewById(R.id.playlists_listview);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        listview.setFastScrollAlwaysVisible(true);
    }
    if (controller.getServer() != null) {
        ArrayList<String> list = new ArrayList<String>();
        for (Playlist p : controller.getSelectedPlaylists()) {
            list.add(p.toString());
        }
        PlaylistArrayAdapter adapter = new PlaylistArrayAdapter(getActivity().getApplicationContext(), list,
                controller.getSelectedPlaylists());
        listview.setAdapter(adapter);
        registerForContextMenu(listview);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
                Playlist selected = controller.getSelectedPlaylists().get(position);

                String urlString = controller.getServer().getHost()
                        + "/server/xml.server.php?action=playlist_songs&auth="
                        + controller.getServer().getAuthKey() + "&filter=" + String.valueOf(selected.getId());
                Log.d("url", urlString);
                controller.getSelectedSongs().clear();
                controller.parsePlaylistSongs(urlString, controller.getSelectedSongs());
                SelectedSongsView newFragment = new SelectedSongsView();
                FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();

                // Replace whatever is in the fragment_container view with this fragment,
                // and add the transaction to the back stack
                transaction.replace(R.id.content_frame, newFragment);
                transaction.addToBackStack(null);
                ((MainActivity) getActivity()).setActiveFragment(6);
                // Commit the transaction
                transaction.commit();
            }

        });
    } else {
        Log.d("bugs", "server null");
    }
    setHasOptionsMenu(true);
    return root;
}

From source file:cn.androidy.materialdesignsample.animations.LayoutChangesActivity.java

private void addItem() {
    // Instantiate a new "row" view.
    final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.list_item_example,
            mContainerView, false);/*from  w w  w .  jav a2 s .  c  o m*/

    // Set the text in the new row to a random country.
    ((TextView) newView.findViewById(android.R.id.text1))
            .setText(COUNTRIES[(int) (Math.random() * COUNTRIES.length)]);

    // Set a click listener for the "X" button in the row that will remove the row.
    newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Remove the row from its parent (the container view).
            // Because mContainerView has android:animateLayoutChanges set to true,
            // this removal is automatically animated.
            mContainerView.removeView(newView);

            // If there are no rows remaining, show the empty view.
            if (mContainerView.getChildCount() == 0) {
                findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
            }
        }
    });

    // Because mContainerView has android:animateLayoutChanges set to true,
    // adding this view is automatically animated.
    mContainerView.addView(newView, 0);
}

From source file:com.adithya321.sharesanalysis.fragments.SharePurchaseMainFragment.java

@Nullable
@Override/*  w w  w.j a va  2  s  .  c  om*/
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
        @Nullable final Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.activity_share_purchase, container, false);

    actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    title = actionBar.getTitle().toString();
    tabLayout = (TabLayout) root.findViewById(R.id.tabs);
    window = getActivity().getWindow();

    ViewPager viewPager = (ViewPager) root.findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    tabLayout.setupWithViewPager(viewPager);
    setColors();

    return root;
}

From source file:com.hacktx.android.fragments.AnnouncementFragment.java

@Nullable
@Override// w ww  .  j  a  va 2 s .  c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_announcement, container, false);
    announcements = new ArrayList<>();

    mEmptyLayout = (ConstraintLayout) root.findViewById(R.id.empty_view);

    setupToolbar((Toolbar) root.findViewById(R.id.toolbar), R.string.fragment_announcement_title);

    setupSwipeRefreshLayout(root);
    setupCollapsibleToolbar((AppBarLayout) root.findViewById(R.id.appBar), swipeRefreshLayout);
    setupRecyclerView(root);
    setupEmptyLayout((TextView) root.findViewById(R.id.fragment_empty_title),
            (Button) root.findViewById(R.id.fragment_empty_btn));
    getAnnouncements();

    return root;
}