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.sentaroh.android.BluetoothWidget.Log.LogFileListDialogFragment.java

private void setContextButtonSelecteMode(LogFileListAdapter lfm_adapter) {
    final TextView dlg_title = (TextView) mDialog.findViewById(R.id.log_file_list_dlg_title);
    String sel = "" + lfm_adapter.getItemSelectedCount() + "/" + lfm_adapter.getCount();
    dlg_title.setText(sel);/*  www .j a  v  a  2  s. c  o m*/

    final ImageButton dlg_done = (ImageButton) mDialog.findViewById(R.id.log_file_list_dlg_done);
    dlg_done.setVisibility(ImageButton.VISIBLE);

    LinearLayout ll_prof = (LinearLayout) mDialog.findViewById(R.id.log_context_view);
    LinearLayout ll_delete = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_delete_view);
    LinearLayout ll_share = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_share_view);
    LinearLayout ll_rotate_log = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_rotate_log_view);
    LinearLayout ll_select_all = (LinearLayout) ll_prof.findViewById(R.id.log_context_button_select_all_view);
    LinearLayout ll_unselect_all = (LinearLayout) ll_prof
            .findViewById(R.id.log_context_button_unselect_all_view);

    ll_rotate_log.setVisibility(LinearLayout.GONE);

    boolean deletable_log_selected = false;
    for (int i = 0; i < lfm_adapter.getCount(); i++) {
        if (lfm_adapter.getItem(i).isChecked && !lfm_adapter.getItem(i).isCurrentLogFile) {
            deletable_log_selected = true;
            break;
        }
    }
    if (deletable_log_selected)
        ll_delete.setVisibility(LinearLayout.VISIBLE);
    else
        ll_delete.setVisibility(LinearLayout.GONE);

    if (lfm_adapter.getItemSelectedCount() > 0)
        ll_share.setVisibility(LinearLayout.VISIBLE);
    else
        ll_share.setVisibility(LinearLayout.GONE);

    ll_select_all.setVisibility(LinearLayout.VISIBLE);
    if (lfm_adapter.isAnyItemSelected())
        ll_unselect_all.setVisibility(LinearLayout.VISIBLE);
    else
        ll_unselect_all.setVisibility(LinearLayout.GONE);
}

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

private void displayExponential(LayoutInflater inflater) {
    if (inputType == inputType_T && fnResult != null && fnResult.exponential != null) {
        // Also display exponential
        String exponentialLabel = "For T>0, add correction term:";
        Savelog.d(TAG, debug, "Exponential term=" + exponentialLabel);
        if (mExponentLabelView != null) {
            mExponentLabelView.setText(exponentialLabel);
            mExponentLabelView.setVisibility(View.VISIBLE);
        }//  w w w.  j a v  a  2  s.  c  o  m
        String data = String.format("%.3f", fnResult.E);
        CharSequence exponentConclude = TextUtils.concat(getText(R.string.label_E_typeK), " = ", data);
        if (mExponentConcludeView != null) {
            mExponentConcludeView.setText(exponentConclude);
            mExponentConcludeView.setVisibility(View.VISIBLE);
        }
    } else {
        if (mExponentLabelView != null)
            mExponentLabelView.setVisibility(View.GONE);
        if (mExponentConcludeView != null)
            mExponentConcludeView.setVisibility(View.GONE);
    }

    LinearLayout parent = mExponentialView;

    // Remove any existing table
    TableLayout tableLayoutE;
    if (tableExponential_Id != 0) {
        tableLayoutE = (TableLayout) parent.findViewById(tableExponential_Id);
        parent.removeView(tableLayoutE);
        tableExponential_Id = 0;
    }

    // Handle exponential term if exists
    if (inputType == inputType_T && fnResult != null && fnResult.exponential != null) {
        if (inflater == null) {
            inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        tableExponential_Id = R.id.tableExponential_id;
        View view = inflater.inflate(R.layout.table_exponent, parent, true);
        tableLayoutE = (TableLayout) view.findViewById(tableExponential_Id);

        int cell_id;
        TextView cell;

        for (int row = 0; row <= 2; row++) {
            int term = row;
            cell_id = ExponentialTable.cell_ids[row][1];
            cell = (TextView) tableLayoutE.findViewById(cell_id);
            cell.setText("" + fnResult.exponential.getTerm(term));
        }

        // T
        cell_id = ExponentialTable.cell_ids[3][1];
        cell = (TextView) tableLayoutE.findViewById(cell_id);
        cell.setText("" + fnResult.Tinput);

        // correction
        cell_id = ExponentialTable.result_ids[1];
        cell = (TextView) tableLayoutE.findViewById(cell_id);
        String correction = String.format("%.3f", fnResult.correction);
        cell.setText("" + correction);
    }
}

From source file:org.matrix.console.activity.SettingsActivity.java

/**
 * Return the edited username for a dedicated session.
 * @param session the session/*from ww w .j a  v a 2  s .  c o m*/
 * @return the edited text
 */
private String getEditedUserName(final MXSession session) {
    LinearLayout linearLayout = mLinearLayoutByMatrixId.get(session.getCredentials().userId);
    EditText displayNameEditText = (EditText) linearLayout.findViewById(R.id.editText_displayName);

    if (!TextUtils.isEmpty(displayNameEditText.getText())) {
        // trim the text to avoid trailing /n after a c+p
        return displayNameEditText.getText().toString().trim();
    }

    return "";
}

From source file:im.vector.activity.SettingsActivity.java

@Override
protected void onResume() {
    super.onResume();

    MyPresenceManager.advertiseAllOnline();

    for (MXSession session : Matrix.getMXSessions(this)) {
        final MyUser myUser = session.getMyUser();
        final MXSession fSession = session;

        final LinearLayout linearLayout = mLinearLayoutBySession.get(fSession);

        final View refreshingView = linearLayout.findViewById(R.id.profile_mask);
        refreshingView.setVisibility(View.VISIBLE);

        session.getProfileApiClient().displayname(myUser.userId, new SimpleApiCallback<String>(this) {
            @Override/*from ww w.jav  a2s . c om*/
            public void onSuccess(String displayname) {

                if ((null != displayname) && !displayname.equals(myUser.displayname)) {
                    myUser.displayname = displayname;
                    EditText displayNameEditText = (EditText) linearLayout
                            .findViewById(R.id.editText_displayName);
                    displayNameEditText.setText(myUser.displayname);
                }

                fSession.getProfileApiClient().avatarUrl(myUser.userId, new SimpleApiCallback<String>(this) {
                    @Override
                    public void onSuccess(String avatarUrl) {
                        if ((null != avatarUrl) && !avatarUrl.equals(myUser.avatarUrl)) {
                            mTmpThumbnailUriBySession.remove(fSession);

                            myUser.avatarUrl = avatarUrl;
                            refreshProfileThumbnail(fSession, linearLayout);
                        }

                        refreshingView.setVisibility(View.GONE);
                    }
                });
            }
        });
    }

    // refresh the cache size
    Button clearCacheButton = (Button) findViewById(R.id.button_clear_cache);
    clearCacheButton.setText(getString(R.string.clear_cache) + " (" + computeApplicationCacheSize() + ")");

    refreshGCMEntries();
}

From source file:com.sentaroh.android.BluetoothWidget.Log.LogFileListDialogFragment.java

private void setContextButtonListener() {
    LinearLayout ll_prof = (LinearLayout) mDialog.findViewById(R.id.log_context_view);
    ImageButton ib_delete = (ImageButton) ll_prof.findViewById(R.id.log_context_button_delete);
    ImageButton ib_share = (ImageButton) ll_prof.findViewById(R.id.log_context_button_share);
    ImageButton ib_rotate_log = (ImageButton) ll_prof.findViewById(R.id.log_context_button_rotate_log);
    ImageButton ib_select_all = (ImageButton) ll_prof.findViewById(R.id.log_context_button_select_all);
    ImageButton ib_unselect_all = (ImageButton) ll_prof.findViewById(R.id.log_context_button_unselect_all);
    final ImageButton dlg_done = (ImageButton) mDialog.findViewById(R.id.log_file_list_dlg_done);

    dlg_done.setOnClickListener(new OnClickListener() {
        @Override//w w  w  .java2s  .co  m
        public void onClick(View v) {
            mLogFileManagementAdapter.setAllItemChecked(false);
            mLogFileManagementAdapter.setShowCheckBox(false);
            mLogFileManagementAdapter.notifyDataSetChanged();
            setContextButtonNormalMode(mLogFileManagementAdapter);
        }
    });

    ib_delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            confirmDeleteLogFile(mLogFileManagementAdapter);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, ib_delete,
            mContext.getString(R.string.msgs_log_file_list_label_delete));

    ib_share.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sendLogFile(mLogFileManagementAdapter);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, ib_share,
            mContext.getString(R.string.msgs_log_file_list_label_share));

    ib_rotate_log.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            rotateLogFile(mLogFileManagementAdapter);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, ib_rotate_log,
            mContext.getString(R.string.msgs_log_file_list_label_rotate_log));

    ib_select_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mLogFileManagementAdapter.setAllItemChecked(true);
            mLogFileManagementAdapter.setShowCheckBox(true);
            setContextButtonSelecteMode(mLogFileManagementAdapter);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, ib_select_all,
            mContext.getString(R.string.msgs_log_file_list_label_select_all));

    ib_unselect_all.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mLogFileManagementAdapter.setAllItemChecked(false);
            //            mLogFileManagementAdapter.setShowCheckBox(false);
            //            setContextButtonNormalMode(mLogFileManagementAdapter);
        }
    });
    ContextButtonUtil.setButtonLabelListener(mContext, ib_unselect_all,
            mContext.getString(R.string.msgs_log_file_list_label_unselect_all));

}

From source file:io.ordunaleon.lumios.ui.DrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer);

    // Find and setup Toolbar to replace the ActionBar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w  w  w . j  a  v a  2 s . c o  m

    // Find and setup DrawerLayout and it's ActionBarDrawerToggle.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open,
            R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Find and setup NavigationView.
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);

    // Find NavigationView header.
    View headerView = navigationView.getHeaderView(0);

    // Make clickable the text in the headerView.
    LinearLayout headerTitle = (LinearLayout) headerView.findViewById(R.id.drawer_header_title);
    headerTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Todo: Allow the user to change the fare rather than display a Snackbar.
            View view = v.getRootView().findViewById(R.id.frame_layout);
            Snackbar.make(view, "WIP | Select your fare", Snackbar.LENGTH_SHORT).show();
        }
    });

    // Find and setup the headerView text.
    mDrawerHeaderHead = (TextView) headerTitle.findViewById(R.id.drawer_header_head);
    mDrawerHeaderSubhead = (TextView) headerTitle.findViewById(R.id.drawer_header_subhead);
    updateDrawerHeader();

    // First run of the app starts with the Navigation Drawer open.
    if (!PrefUtils.isWelcomeDone(this)) {
        PrefUtils.setWelcomeDone(this, true);
        mDrawerLayout.openDrawer(GravityCompat.START);
    }

    if (savedInstanceState == null) {
        onNavigationItemSelected(navigationView.getMenu().findItem(DEFAULT_DRAWER_ITEM_ID));
    } else {
        setTitle(savedInstanceState.getCharSequence(KEY_STATE_TITLE));
    }

    // Check for Google Play Services and start LumiosRegistrationIntentService to register this
    // application with GCM if needed.
    if (checkPlayServices() && !PrefUtils.isAppRegistered(this)) {
        Intent intent = new Intent(this, LumiosRegistrationIntentService.class);
        startService(intent);
    }

    PrefUtils.registerOnSharedPreferenceChangeListener(this, this);
}

From source file:de.azapps.mirakel.new_ui.dialogs.PriorityDialog.java

@Nullable
@Override/* w  ww. java  2s.  com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout v = (LinearLayout) inflater.inflate(R.layout.priority_dialog, null);
    ButterKnife.inject(v);
    if (initialPriority.isPresent()) {
        final @IdRes int checkedID;
        switch (initialPriority.get()) {
        case -1:
        case -2:
            checkedID = R.id.wrapper_priority_low;
            break;
        case 1:
            checkedID = R.id.wrapper_priority_high;
            break;
        case 2:
            checkedID = R.id.wrapper_priority_veryhigh;
            break;
        case 0:
        default:
            checkedID = R.id.wrapper_priority_normal;
            break;
        }
        ((RadioButton) v.findViewById(checkedID).findViewById(R.id.radio_priority)).setChecked(true);
    }
    for (int i = 0; i < v.getChildCount(); i++) {
        v.getChildAt(i).setOnClickListener(this);
    }
    return v;
}

From source file:org.sufficientlysecure.keychain.ui.SettingsActivity.java

/**
 * Hack to get Toolbar in PreferenceActivity. See http://stackoverflow.com/a/26614696
 *///from  w  ww.  j av  a2 s  .co  m
private void setupToolbar() {
    ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    LinearLayout content = (LinearLayout) root.getChildAt(0);
    LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.preference_toolbar, null);

    root.removeAllViews();
    toolbarContainer.addView(content);
    root.addView(toolbarContainer);

    Toolbar toolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar);

    toolbar.setTitle(R.string.title_preferences);
    // noinspection deprecation, TODO use alternative in API level 21
    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //What to do on back clicked
            finish();
        }
    });
}

From source file:im.vector.activity.SettingsActivity.java

private void saveChanges(final MXSession session) {
    LinearLayout linearLayout = mLinearLayoutBySession.get(session);
    EditText displayNameEditText = (EditText) linearLayout.findViewById(R.id.editText_displayName);

    // Save things
    final String nameFromForm = displayNameEditText.getText().toString();

    final ApiCallback<Void> changeCallback = UIUtils.buildOnChangeCallback(this);

    final MyUser myUser = session.getMyUser();
    final Button saveButton = (Button) linearLayout.findViewById(R.id.button_save);

    if (UIUtils.hasFieldChanged(myUser.displayname, nameFromForm)) {
        myUser.updateDisplayName(nameFromForm, new SimpleApiCallback<Void>(changeCallback) {
            @Override//from   ww w  .  ja v  a  2 s  .  c o  m
            public void onSuccess(Void info) {
                super.onSuccess(info);
                updateSaveButton(saveButton);
            }
        });
    }

    Uri newAvatarUri = mTmpThumbnailUriBySession.get(session);

    if (newAvatarUri != null) {
        Log.d(LOG_TAG, "Selected image to upload: " + newAvatarUri);
        ResourceUtils.Resource resource = ResourceUtils.openResource(this, newAvatarUri);
        if (resource == null) {
            Toast.makeText(SettingsActivity.this, getString(R.string.settings_failed_to_upload_avatar),
                    Toast.LENGTH_LONG).show();
            return;
        }

        final ProgressDialog progressDialog = ProgressDialog.show(this, null,
                getString(R.string.message_uploading), true);

        session.getContentManager().uploadContent(resource.contentStream, null, resource.mimeType, null,
                new ContentManager.UploadCallback() {
                    @Override
                    public void onUploadProgress(String anUploadId, int percentageProgress) {
                        progressDialog.setMessage(
                                getString(R.string.message_uploading) + " (" + percentageProgress + "%)");
                    }

                    @Override
                    public void onUploadComplete(String anUploadId, ContentResponse uploadResponse,
                            final int serverResponseCode, String serverErrorMessage) {
                        if (uploadResponse == null) {
                            Toast.makeText(SettingsActivity.this,
                                    (null != serverErrorMessage) ? serverErrorMessage
                                            : getString(R.string.settings_failed_to_upload_avatar),
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Log.d(LOG_TAG, "Uploaded to " + uploadResponse.contentUri);
                            myUser.updateAvatarUrl(uploadResponse.contentUri,
                                    new SimpleApiCallback<Void>(changeCallback) {
                                        @Override
                                        public void onSuccess(Void info) {
                                            super.onSuccess(info);
                                            // Reset this because its being set is how we know there's been a change
                                            mTmpThumbnailUriBySession.remove(session);
                                            updateSaveButton(saveButton);
                                        }
                                    });
                        }
                        progressDialog.dismiss();
                    }
                });
    }
}

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

private void showDialog(final int type) {
    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity());
    @SuppressLint("InflateParams") // the layout is used inside a dialog so no parent is needed
    LinearLayout layout = (LinearLayout) getActivity().getLayoutInflater()
            .inflate(R.layout.widget_schedule_task_dialog, null);
    if (type == TYPE_ONE_OFF) {
        alertBuilder.setTitle(R.string.scheduler_add_oneoff);
        alertBuilder.setMessage(R.string.scheduler_add_oneoff_message);
        alertBuilder.setPositiveButton(R.string.scheduler_add_oneoff, null);
        ((TextView) layout.findViewById(R.id.task_param1_title)).setText(R.string.scheduler_run_from);
        ((TextView) layout.findViewById(R.id.task_param2_title)).setText(R.string.scheduler_run_by);
    } else {/*from  ww w  .  j  a  v a2  s.c  o  m*/
        alertBuilder.setTitle(R.string.scheduler_add_periodic);
        alertBuilder.setMessage(R.string.scheduler_add_periodic_message);
        alertBuilder.setPositiveButton(R.string.scheduler_add_periodic, null);
        ((TextView) layout.findViewById(R.id.task_param1_title)).setText(R.string.scheduler_period);
        ((TextView) layout.findViewById(R.id.task_param2_title)).setText(R.string.scheduler_flex);
    }
    final EditText param1View = (EditText) layout.findViewById(R.id.task_param1);
    final EditText param2View = (EditText) layout.findViewById(R.id.task_param2);
    final RadioGroup connectivityView = (RadioGroup) layout.findViewById(R.id.task_connectivity_group);
    final CheckBox chargingView = (CheckBox) layout.findViewById(R.id.task_charging_checkbox);
    final CheckBox persistenceView = (CheckBox) layout.findViewById(R.id.task_persistence_checkbox);
    alertBuilder.setView(layout);
    alertBuilder.setNegativeButton(R.string.scheduler_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });
    // Show the dialog
    final AlertDialog dialog = alertBuilder.create();
    dialog.show();
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // schedule the task
            final long value1;
            final long value2;
            try {
                value1 = Long.parseLong(param1View.getText().toString());
                value2 = Long.parseLong(param2View.getText().toString());
            } catch (NumberFormatException e) {
                Toast.makeText(getActivity(), getString(R.string.scheduler_error_nan), Toast.LENGTH_SHORT)
                        .show();
                return;
            }
            int connectivity = Task.NETWORK_STATE_CONNECTED;
            switch (connectivityView.getCheckedRadioButtonId()) {
            case R.id.task_connectivity_connected:
                connectivity = Task.NETWORK_STATE_CONNECTED;
                break;
            case R.id.task_connectivity_unmetered:
                connectivity = Task.NETWORK_STATE_UNMETERED;
                break;
            case R.id.task_connectivity_any:
                connectivity = Task.NETWORK_STATE_ANY;
                break;
            }
            boolean charging = chargingView.isChecked();
            boolean persistence = persistenceView.isChecked();
            if (type == TYPE_ONE_OFF) {
                addOneOff(value1, value2, connectivity, charging);
            } else {
                addPeriodic(value1, value2, connectivity, charging, persistence);
            }
            refresh();
            dialog.dismiss();
        }
    });
}