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:gov.wa.wsdot.android.wsdot.ui.borderwait.BorderWaitNorthboundFragment.java

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

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_recycler_list_with_swipe_refresh, null);

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);

    mAdapter = new BorderWaitNorthboundFragment.BorderWaitAdapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);/*from  w  w w.  jav  a 2 s.  c  om*/

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    swipeRefreshLayout.setRefreshing(true);

    viewModel = ViewModelProviders.of(this, viewModelFactory).get(BorderWaitViewModel.class);

    viewModel.init(BorderWaitViewModel.BorderDirection.NORTHBOUND);

    viewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show();
            }
        }
    });

    viewModel.getBorderWaits().observe(this, borderWaits -> {
        if (borderWaits.size() > 0) {
            mBorderWaits.clear();
            mBorderWaits = borderWaits;
            mAdapter.notifyDataSetChanged();
        }
    });

    mEmptyView = root.findViewById(R.id.empty_list_view);

    return root;
}

From source file:com.conferenceengineer.android.iosched.ui.SessionFeedbackFragment.java

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

    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_session_feedback, null);

    mTitle = (TextView) rootView.findViewById(R.id.session_title);

    mSessionRatingFeedbackBar = RatingBarHelper.create(rootView.findViewById(R.id.session_rating_container));
    mQ1FeedbackBar = RatingBarHelper.create(rootView.findViewById(R.id.session_feedback_q1_container));
    mQ2FeedbackBar = RatingBarHelper.create(rootView.findViewById(R.id.session_feedback_q2_container));
    mQ3FeedbackBar = RatingBarHelper.create(rootView.findViewById(R.id.session_feedback_q3_container));

    mQ4RadioGroup = (RadioGroup) rootView.findViewById(R.id.session_feedback_q4);

    mComments = (EditText) rootView.findViewById(R.id.session_feedback_comments);

    if (mVariableHeightHeader) {
        View headerView = rootView.findViewById(R.id.header_session);
        ViewGroup.LayoutParams layoutParams = headerView.getLayoutParams();
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        headerView.setLayoutParams(layoutParams);
    }/*from w w  w  . j av  a  2  s .  c om*/

    rootView.findViewById(R.id.submit_feedback_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            submitAllFeedback();
            LOGD("Tracker", "Feedback: " + mTitleString);
            getActivity().finish();
        }
    });
    return rootView;
}

From source file:com.jun.elephant.ui.topic.list.TopicListByForumFragment.java

public void refreshUI() {
    TypedValue badgeColor = new TypedValue();
    TypedValue floatBtnColor = new TypedValue();
    Resources.Theme theme = getContext().getTheme();
    theme.resolveAttribute(R.attr.elephantBadge, badgeColor, true);
    theme.resolveAttribute(R.attr.elephantFloatBtn, floatBtnColor, true);

    int childCount = mRecyclerView.getChildCount();
    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        ViewGroup childView = (ViewGroup) mRecyclerView.getChildAt(childIndex);
        BGABadgeRelativeLayout bgarl = (BGABadgeRelativeLayout) childView.findViewById(R.id.bgaRl);
        bgarl.getBadgeViewHelper()/*from  w  ww.j ava2  s.c o  m*/
                .setBadgeBgColorInt(ContextCompat.getColor(getContext(), badgeColor.resourceId));

    }

    mFabBtn.setColorNormalResId(floatBtnColor.resourceId);
    mFabBtn.setColorPressedResId(floatBtnColor.resourceId);

    // RecyclerView  Pool  Item 
    //ListView????? AbsListView  RecycleBin ????? clear 
    Class<RecyclerView> recyclerViewClass = RecyclerView.class;
    try {
        Field declaredField = recyclerViewClass.getDeclaredField("mRecycler");
        declaredField.setAccessible(true);
        Method declaredMethod = Class.forName(RecyclerView.Recycler.class.getName()).getDeclaredMethod("clear",
                (Class<?>[]) new Class[0]);
        declaredMethod.setAccessible(true);
        declaredMethod.invoke(declaredField.get(mRecyclerView), new Object[0]);
        RecyclerView.RecycledViewPool recycledViewPool = mRecyclerView.getRecycledViewPool();
        recycledViewPool.clear();

    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.google.cast.samples.games.gamedebugger.PlayerTransitionDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();

    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.player_transition_dialog, null);
    mTransitionPlayerStateSection = (LinearLayout) view.findViewById(R.id.transition_player_state_section);
    mPlayerStateGroup = (RadioGroup) view.findViewById(R.id.radio_player_states);
    mExtraMessageDataLabel = (TextView) view.findViewById(R.id.extra_message_data_label);
    mExtraMessageDataEditText = (EditText) view.findViewById(R.id.extra_message_data);
    mCancelButton = (Button) view.findViewById(R.id.button_cancel);
    mOkButton = (Button) view.findViewById(R.id.button_ok);

    // Find the valid player states.
    GameManagerClient client = GameDebuggerApplication.getInstance().getCastConnectionManager()
            .getGameManagerClient();//from w w  w  . j  a  v a 2  s .c  om
    GameManagerState state = client.getCurrentState();
    PlayerInfo player = state.getPlayer(getArguments().getString(KEY_PLAYER_ID));
    if (player == null) {
        return null;
    }
    if (player.isConnected()) {
        boolean defaultSelectionSet = false;
        for (int i = 0; i < PLAYER_STATES.length; i++) {
            if (PLAYER_STATES[i] != player.getPlayerState()) {
                RadioButton radioButton = new RadioButton(getActivity());
                radioButton.setText(getText(PLAYER_STATE_RESOURCE_IDS[i]));
                radioButton.setId(PLAYER_STATES[i]);
                radioButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT));
                mPlayerStateGroup.addView(radioButton);

                // Select the first element.
                if (!defaultSelectionSet) {
                    mPlayerStateGroup.check(PLAYER_STATES[i]);
                    defaultSelectionSet = true;
                }
            }
        }
    } else {
        RadioButton radioButton = new RadioButton(getActivity());
        radioButton.setText(getText(R.string.player_state_available));
        radioButton.setId(GameManagerClient.PLAYER_STATE_AVAILABLE);
        radioButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        mPlayerStateGroup.addView(radioButton);
        mPlayerStateGroup.check(GameManagerClient.PLAYER_STATE_AVAILABLE);
    }

    if (!getArguments().getBoolean(KEY_IS_TRANSITION)) {
        mTransitionPlayerStateSection.setVisibility(View.GONE);
        mExtraMessageDataLabel.setText(R.string.game_message_label);
        mExtraMessageDataEditText.setMinLines(4);
        mOkButton.setText(getText(R.string.button_send_game_message));

    }
    builder.setView(view);

    mCancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    mOkButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onOkPressed();
        }
    });

    return builder.create();
}

From source file:com.bullmobi.base.ui.fragments.dialogs.FeedbackDialog.java

/**
 * Initialize Frequently asked questions panel. This panel is here to reduce
 * the number of already answered questions.
 *//*  w w  w  .  ja  v  a  2 s.  com*/
private void initFaqPanel(@NonNull ViewGroup root) {
    mFaqContainer = ((ViewStub) root.findViewById(R.id.faq)).inflate();
    mFaqContainer.findViewById(R.id.faq).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActionBarActivity activity = (ActionBarActivity) getActivity();
            DialogHelper.showHelpDialog(activity);
        }
    });
}

From source file:angeloid.dreamnarae.Delete_Main.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.tab_tab2_delete, null);
    deletei = (Button) root.findViewById(R.id.tab_tab2_delete_reboot_ok);
    deleteii = (Button) root.findViewById(R.id.tab_tab2_delete_reboot_no);
    progresstext_delete = (TextView) root.findViewById(R.id.tab_tab2_delete_running);
    progresstext_delete.setTypeface(Tab_MainActivity.Fonts.THEOREM);
    deletei.setTypeface(Tab_MainActivity.Fonts.THEOREM);
    deleteii.setTypeface(Tab_MainActivity.Fonts.THEOREM);

    deletei.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            v.postDelayed(new Runnable() {
                public void run() {
                    DialogProgress(false);
                }/*from  w  w  w  . j  ava 2s .  c o m*/
            }, 10); // 0.01      
        }
    });
    deleteii.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            v.postDelayed(new Runnable() {
                public void run() {
                    DialogProgress2(false);
                }
            }, 10); // 0.01      
        }
    });
    return root;
}

From source file:org.dmfs.android.colorpicker.PaletteFragment.java

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

    /*/* w ww .  ja  v a2 s . com*/
       * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar
     */
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_grid,
            container, false);
    final GridView gridview = (GridView) rootView.findViewById(android.R.id.content);

    mAdapter = new PaletteGridAdapter(getActivity(), mPalette);
    gridview.setAdapter(mAdapter);
    gridview.setOnItemClickListener(this);
    gridview.setNumColumns(mAdapter.getNumColumns());

    /*
       * Adjust the layout of the gridview to a square.
     *
     * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/
     */
    gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom();
            int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight();

            int gridWidth = Math.min(parentWidth, parentHeight);

            int columnSpacing;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1);
            } else {
                /*
                * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use
                * a hard coded value of 8 dip.
                *
                * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step
                * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value?
                */
                DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics();
                if (android.os.Build.VERSION.SDK_INT > 10) {
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * (mAdapter.getNumColumns() - 1);
                } else {
                    // Android 2 seems to add spacing around the entire gridview
                    columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics)
                            * mAdapter.getNumColumns();
                }
            }

            // width of a single column
            int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns();

            // estimated width of the grid
            int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing;

            // add padding to center the grid if we don't use the entire space due to rounding errors
            if (actualGridWidth < gridWidth - 1) {
                int padding = (gridWidth - actualGridWidth) / 2;
                if (padding > 0) {
                    gridview.setPadding(padding, padding, padding, padding);

                }
            } else {
                // no padding needed
                gridview.setPadding(0, 0, 0, 0);
            }

            // set the column width
            gridview.setColumnWidth(columnWidth);

            android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams();
            if (params == null || params.height != gridWidth) // avoid unnecessary updates
            {
                LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth);
                gridview.setLayoutParams(lparams);
            }
        }
    });
    return rootView;
}

From source file:com.limitfan.gojuuon.utils.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(com.limitfan.gojuuon.R.layout.detail_slide_page,
            container, false);//from   w w  w .  j a v  a2s  .  co  m

    ImageView stroke = (ImageView) (rootView.findViewById(com.limitfan.gojuuon.R.id.stroke));
    String romaji = Common.roma[getPageNumber()];

    try {
        String img = "";
        if (ActKana.isHira)
            img = "kanagraph/hiragana_" + romaji + ".jpg";
        else
            img = "kanagraph/katakana_" + romaji + ".jpg";
        InputStream is = getContext().getAssets().open(img, AssetManager.ACCESS_STREAMING);

        Bitmap bm = BitmapFactory.decodeStream(is);
        stroke.setImageBitmap(bm);
    } catch (Exception e) {

    }

    ViewGroup listView = (ViewGroup) rootView.findViewById(com.limitfan.gojuuon.R.id.list);
    ViewGroup demo_speak = (ViewGroup) inflater.inflate(com.limitfan.gojuuon.R.layout.demo_list_item, null);
    ((TextView) demo_speak.findViewById(com.limitfan.gojuuon.R.id.text))
            .setText(com.limitfan.gojuuon.R.string.demo);
    ((ImageView) demo_speak.findViewById(com.limitfan.gojuuon.R.id.icon))
            .setImageResource(com.limitfan.gojuuon.R.drawable.speak_off);

    listView.addView(demo_speak);

    TextView sample = (TextView) (rootView.findViewById(com.limitfan.gojuuon.R.id.sample));
    setSample(sample);
    demo_speak.setOnClickListener(new SpeakListener());

    //stroke.setImageResource();

    // Set the title view to show the page number.
    //EditText main = ((EditText) rootView.findViewById(R.id.Description));
    // main.setText(getString(R.string.title_template_step, mPageNumber + 1));
    //main.setEnabled(false);
    // main.setBackgroundColor(Color.TRANSPARENT);
    // main.setText(getFromAssets("details/"+(mPageNumber+1)+".txt"));

    return rootView;
}

From source file:com.achep.base.ui.fragments.dialogs.FeedbackDialog.java

/**
 * Initialize Frequently asked questions panel. This panel is here to reduce
 * the number of already answered questions.
 *//*from  www  .ja  va  2  s . c o  m*/
private void initFaqPanel(@NonNull ViewGroup root) {
    mFaqContainer = ((ViewStub) root.findViewById(R.id.faq)).inflate();
    mFaqContainer.findViewById(R.id.faq).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AppCompatActivity activity = (AppCompatActivity) getActivity();
            DialogHelper.showHelpDialog(activity);
        }
    });
}

From source file:com.jaspersoft.android.jaspermobile.dialog.NumberPickerDialogFragment.java

@NonNull
@Override//from   www .j  av a  2  s  . c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ViewGroup customView = (ViewGroup) LayoutInflater.from(getActivity()).inflate(R.layout.number_dialog_layout,
            (ViewGroup) getView(), false);

    numberPicker = (NumberPicker) customView.findViewById(R.id.numberPicker);
    numberPicker.setMinValue(mMinValue);
    numberPicker.setMaxValue(mMaxValue);

    int inputId = getActivity().getResources().getIdentifier("numberpicker_input", "id", "android");
    etNumber = (EditText) numberPicker.findViewById(inputId);
    etNumber.addTextChangedListener(new PickerTextWatcher());

    builder.setTitle(R.string.dialog_current_page);
    builder.setView(customView);
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.ok, this);
    builder.setNegativeButton(R.string.cancel, this);

    AlertDialog dialog = builder.create();
    if (savedInstanceState == null) {
        dialog.setOnShowListener(this);
    }

    return dialog;
}