Example usage for android.widget LinearLayout findViewById

List of usage examples for android.widget LinearLayout findViewById

Introduction

In this page you can find the example usage for android.widget LinearLayout 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:com.roughike.swipeselector.SwipeAdapter.java

/**
 * Override methods / listeners/*from  w  ww.j  a  v a  2 s .c  o  m*/
 */
@Override
public Object instantiateItem(ViewGroup container, int position) {
    LinearLayout layout = (LinearLayout) View.inflate(mContext, R.layout.swipeselector_content_item, null);
    TextView title = (TextView) layout.findViewById(R.id.swipeselector_content_title);
    TextView description = (TextView) layout.findViewById(R.id.swipeselector_content_description);

    SwipeItem slideItem = mItems.get(position);
    title.setText(slideItem.title);
    description.setText(slideItem.description);

    // We shouldn't get here if the typeface didn't exist.
    // But just in case, because we're paranoid.
    if (mCustomTypeFace != null) {
        title.setTypeface(mCustomTypeFace);
        description.setTypeface(mCustomTypeFace);
    }

    if (mTitleTextAppearance != -1) {
        setTextAppearanceCompat(title, mTitleTextAppearance);
    }

    if (mDescriptionTextAppearance != -1) {
        setTextAppearanceCompat(description, mDescriptionTextAppearance);
    }

    layout.setPadding(mContentLeftPadding, mSweetSixteen, mContentRightPadding, mSweetSixteen);

    container.addView(layout);
    return layout;
}

From source file:org.mklab.mikity.android.SampleSelectionFragment.java

/**
 * ????????/*from ww  w . j a va 2s .co m*/
 */
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.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java

private void createSharableBitmap() {
    Bitmap sharableBitmap = Bitmap.createBitmap(getView().getWidth(), getView().getHeight(),
            Bitmap.Config.ARGB_8888);/*from  w ww  .  j a v  a  2s .c o  m*/
    Canvas canvas = new Canvas(sharableBitmap);
    canvas.drawColor(ContextCompat.getColor(getContext(), R.color.white));

    // Load the view for the sharable. This will be drawn to the bitmap
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_sharable_tongue_twister, null);

    TextView textView = (TextView) layout.findViewById(R.id.twister_sharable_tongue_twister);
    textView.setText(mQuestion);

    textView = (TextView) layout.findViewById(R.id.twister_sharable_i_said);
    textView.setText(mUnderstoodText);

    textView = (TextView) layout.findViewById(R.id.mimic_twister_share_success);
    textView.setText(mSuccessMessage);

    // Perform the layout using the dimension of the bitmap
    int widthSpec = View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY);
    layout.measure(widthSpec, heightSpec);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    // Draw the generated view to canvas
    layout.draw(canvas);

    String title = getString(R.string.app_short_name) + ": " + getString(R.string.mimic_twister_name);
    mSharableUri = ShareFragment.saveShareableBitmap(getActivity(), sharableBitmap, title);
}

From source file:org.tomahawk.tomahawk_android.dialogs.RedirectConfigDialog.java

/**
 * Called when this {@link android.support.v4.app.DialogFragment} is being created
 *///from  w ww  . ja  va 2 s  . c om
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().containsKey(TomahawkFragment.PREFERENCEID)) {
        String id = getArguments().getString(TomahawkFragment.PREFERENCEID);
        mScriptResolver = (ScriptResolver) PipeLine.get().getResolver(id);
        mAuthenticatorUtils = AuthenticatorManager.get().getAuthenticatorUtils(id);
    }

    TextView headerTextView = (TextView) addScrollingViewToFrame(R.layout.config_textview);
    headerTextView.setText(mScriptResolver.getDescription());

    int buttonBackgroundResId;
    int buttonTextColor;
    View.OnClickListener onClickListener;
    switch (mScriptResolver.getId()) {
    case TomahawkApp.PLUGINNAME_RDIO:
        buttonBackgroundResId = R.drawable.selectable_background_tomahawk_rectangle_gray;
        buttonTextColor = getResources().getColor(R.color.primary_textcolor);
        onClickListener = new RedirectButtonListener(TomahawkApp.PLUGINNAME_RDIO);
        break;
    case TomahawkApp.PLUGINNAME_SPOTIFY:
        buttonBackgroundResId = R.drawable.selectable_background_tomahawk_rectangle_gray;
        buttonTextColor = getResources().getColor(R.color.primary_textcolor);
        onClickListener = new RedirectButtonListener(TomahawkApp.PLUGINNAME_SPOTIFY);
        break;
    default:
        buttonBackgroundResId = R.drawable.selectable_background_deezer_button;
        buttonTextColor = getResources().getColor(R.color.primary_textcolor_inverted);
        onClickListener = new RedirectButtonListener(TomahawkApp.PLUGINNAME_DEEZER);
        break;
    }

    View buttonLayout = addScrollingViewToFrame(R.layout.config_redirect_button);
    LinearLayout button = ((LinearLayout) buttonLayout.findViewById(R.id.config_redirect_button));
    button.setBackgroundResource(buttonBackgroundResId);
    ImageView buttonImage = (ImageView) buttonLayout.findViewById(R.id.config_redirect_button_image);
    mScriptResolver.loadIcon(buttonImage, false);
    mRedirectButtonTextView = (TextView) button.findViewById(R.id.config_redirect_button_text);
    mRedirectButtonTextView.setTextColor(buttonTextColor);
    mRedirectButtonTextView.setText(mAuthenticatorUtils.isLoggedIn()
            ? getString(R.string.resolver_config_redirect_button_text_log_out_of)
            : getString(R.string.resolver_config_redirect_button_text_log_into));
    button.setOnClickListener(onClickListener);
    setDialogTitle(mScriptResolver.getName());
    hideNegativeButton();
    setStatus(mScriptResolver);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(getDialogView());
    return builder.create();
}

From source file:org.onebusaway.android.report.ui.SimpleArrivalListFragment.java

private void loadArrivalList(ObaArrivalInfo[] info, final ObaReferences refs, long currentTime) {
    LinearLayout contentLayout = (LinearLayout) getActivity().findViewById(R.id.simple_arrival_content);
    contentLayout.removeAllViews();/*from   w  w w  . j  av  a2 s .  c  om*/

    ArrayList<ArrivalInfo> arrivalInfos = ArrivalInfoUtils.convertObaArrivalInfo(getActivity(), info,
            new ArrayList<String>(), currentTime, false);

    for (ArrivalInfo stopInfo : arrivalInfos) {

        final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();

        LayoutInflater inflater = LayoutInflater.from(getActivity());
        LinearLayout view = (LinearLayout) inflater.inflate(R.layout.arrivals_list_item, null, false);
        view.setBackgroundColor(getResources().getColor(R.color.material_background));
        TextView route = (TextView) view.findViewById(R.id.route);
        TextView destination = (TextView) view.findViewById(R.id.destination);
        TextView time = (TextView) view.findViewById(R.id.time);
        TextView status = (TextView) view.findViewById(R.id.status);
        TextView etaView = (TextView) view.findViewById(R.id.eta);
        TextView minView = (TextView) view.findViewById(R.id.eta_min);
        ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator);

        view.findViewById(R.id.more_horizontal).setVisibility(View.INVISIBLE);
        view.findViewById(R.id.route_favorite).setVisibility(View.INVISIBLE);

        String routeShortName = arrivalInfo.getShortName();
        route.setText(routeShortName);
        UIUtils.maybeShrinkRouteName(getActivity(), route, routeShortName);

        destination.setText(UIUtils.formatDisplayText(arrivalInfo.getHeadsign()));
        status.setText(stopInfo.getStatusText());

        long eta = stopInfo.getEta();
        if (eta == 0) {
            etaView.setText(R.string.stop_info_eta_now);
            minView.setVisibility(View.GONE);
        } else {
            etaView.setText(String.valueOf(eta));
            minView.setVisibility(View.VISIBLE);
        }

        status.setBackgroundResource(R.drawable.round_corners_style_b_status);
        GradientDrawable d = (GradientDrawable) status.getBackground();

        Integer colorCode = stopInfo.getColor();
        int color = getActivity().getResources().getColor(colorCode);
        if (stopInfo.getPredicted()) {
            // Show real-time indicator
            UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode,
                    android.R.color.transparent);
            realtimeView.setVisibility(View.VISIBLE);
        } else {
            realtimeView.setVisibility(View.INVISIBLE);
        }

        etaView.setTextColor(color);
        minView.setTextColor(color);
        d.setColor(color);

        // Set padding on status view
        int pSides = UIUtils.dpToPixels(getActivity(), 5);
        int pTopBottom = UIUtils.dpToPixels(getActivity(), 2);
        status.setPadding(pSides, pTopBottom, pSides, pTopBottom);

        time.setText(DateUtils.formatDateTime(getActivity(), stopInfo.getDisplayTime(),
                DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);

        contentLayout.addView(view);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String agencyName = findAgencyNameByRouteId(refs, arrivalInfo.getRouteId());
                mCallback.onArrivalItemClicked(arrivalInfo, agencyName);
            }
        });
    }
}

From source file:com.android.mms.rcs.FavoriteDetailAdapter.java

private void initVcardMagView(LinearLayout linearLayout) {
    ImageView imageView = (ImageView) linearLayout.findViewById(R.id.image_view);
    String fileName = mCursor/*w  ww  . j  a v  a  2  s.c o m*/
            .getString(mCursor.getColumnIndexOrThrow(FavoriteMessageProvider.FavoriteMessage.FILE_NAME));
    String vcardFileName = fileName;
    ArrayList<PropertyNode> propList = RcsMessageOpenUtils.openRcsVcardDetail(mContext, vcardFileName);
    Bitmap bitmap = null;
    for (PropertyNode propertyNode : propList) {
        if ("PHOTO".equals(propertyNode.propName)) {
            if (propertyNode.propValue_bytes != null) {
                byte[] bytes = propertyNode.propValue_bytes;
                bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                bitmap = RcsUtils.decodeInSampleSizeBitmap(bitmap);
                break;
            }
        }
    }
    if (bitmap != null) {
        imageView.setBackgroundDrawable(new BitmapDrawable(bitmap));
    } else {
        imageView.setBackgroundResource(R.drawable.ic_attach_vcard);
    }
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

private View createNewMemberRow(String name, String value) {
    LinearLayout row = (LinearLayout) getLayoutInflater().inflate(R.layout.widget_icon_text_button_row, null);
    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
    Button button = (Button) row.findViewById(R.id.widget_itbr_button);

    icon.setImageResource(R.drawable.smartphone_grey600);
    label.setText(name + ": " + AbstractFragment.truncateToShortString(value));
    button.setText(R.string.group_undo_add_member);
    button.setTag(R.id.tag_action, ACTION_UNDO_ADD_MEMBER);
    button.setTag(R.id.tag_token, name);
    button.setOnClickListener(this);
    return row;/*from w  ww  .  j  av a  2 s.co  m*/
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

private View createRemovedMemberRow(String name, String value) {
    LinearLayout row = (LinearLayout) getLayoutInflater().inflate(R.layout.widget_icon_text_button_row, null);
    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
    Button button = (Button) row.findViewById(R.id.widget_itbr_button);

    icon.setImageResource(R.drawable.smartphone_grey600);
    label.setText(name + ": " + AbstractFragment.truncateToShortString(value));
    button.setText(R.string.group_undo_remove_member);
    button.setTag(R.id.tag_action, ACTION_UNDO_REMOVE_MEMBER);
    button.setTag(R.id.tag_token, name);
    button.setOnClickListener(this);
    return row;//from w  w  w . java 2  s . c o m
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

private View createCurrentMemberRow(String name, String value) {
    LinearLayout row = (LinearLayout) getLayoutInflater().inflate(R.layout.widget_icon_text_button_row, null);
    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
    Button button = (Button) row.findViewById(R.id.widget_itbr_button);

    icon.setImageResource(R.drawable.smartphone_grey600);
    label.setText(name + ": " + AbstractFragment.truncateToShortString(value));
    button.setText(R.string.group_remove_member);
    button.setTag(R.id.tag_action, ACTION_REMOVE_MEMBER);
    button.setTag(R.id.tag_token, name);
    button.setOnClickListener(this);
    return row;/*from w w  w.j  a  v  a 2s.  c  o  m*/
}

From source file:com.rstar.mobile.thermocouple.ui.MenuSmallFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*from  w  w w.  j av a 2  s.  c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_menu_small, parent, false);

    LinearLayout keypadPanel = (LinearLayout) v.findViewById(R.id.fragmentMenu_id);

    for (int index = 0; index < size; index++) {
        // Prepare listener. May reuse if available.
        if (mOnKeyClickListeners[index] == null)
            mOnKeyClickListeners[index] = new OnKeyClickListener(this, index);

        // Hook up panels
        mPanels[index] = (LinearLayout) keypadPanel.findViewById(panel_ids[index][0]);
        mPanels[index].setOnClickListener(mOnKeyClickListeners[index]);

        TextView textView = (TextView) keypadPanel.findViewById(panel_ids[index][1]);
        textView.setText(panelLabel[mTabNumber][index]);
        ImageButton imageButton = (ImageButton) keypadPanel.findViewById(panel_ids[index][2]);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            imageButton.setImageDrawable(
                    getResources().getDrawable(image_ids[mTabNumber][index], getActivity().getTheme()));
        else
            imageButton.setImageDrawable(getResources().getDrawable(image_ids[mTabNumber][index]));
    }
    return v;
}