當前位置: 首頁>>代碼示例>>Java>>正文


Java EditText.getText方法代碼示例

本文整理匯總了Java中android.widget.EditText.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java EditText.getText方法的具體用法?Java EditText.getText怎麽用?Java EditText.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.EditText的用法示例。


在下文中一共展示了EditText.getText方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addSpace

import android.widget.EditText; //導入方法依賴的package包/類
/**
 * 添加間隔
 *
 * @param ed        EditText
 * @param maxLength 有效位數 比如 電話11位
 * @param location  要打間隔的位置
 */
private void addSpace(EditText ed, int maxLength, int... location) {
    Editable s = ed.getText();
    String val = s.toString();
    String valRep = val.replace(" ", "");
    StringBuilder sb = new StringBuilder(valRep);
    for (int m = 0; m < location.length; m++) {
        if (sb.length() > location[m] + m) {
            sb.insert(location[m] + m, " ");
        }
    }
    if (sb.length() > maxLength + location.length) {
        String _s = sb.toString().substring(0, maxLength + location.length);
        ed.setText(_s);
        ed.setSelection(_s.length());
    } else {
        int k = mContent.getSelectionEnd();
        ed.setText(sb);
        ed.setSelection(isSelection ? k : sb.length());
    }
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:28,代碼來源:EditTextWatcher.java

示例2: submitOrder

import android.widget.EditText; //導入方法依賴的package包/類
/**
 * This method is called when the order button is clicked.
 */
public void submitOrder(View view) {
    // Get user's name
    EditText nameField = (EditText) findViewById(R.id.name_field);
    Editable nameEditable = nameField.getText();
    String name = nameEditable.toString();

    // Figure out if the user wants whipped cream topping
    CheckBox whippedCreamCheckBox = (CheckBox) findViewById(R.id.whipped_cream_checkbox);
    boolean hasWhippedCream = whippedCreamCheckBox.isChecked();

    // Figure out if the user wants choclate topping
    CheckBox chocolateCheckBox = (CheckBox) findViewById(R.id.chocolate_checkbox);
    boolean hasChocolate = chocolateCheckBox.isChecked();

    // Calculate the price
    int price = calculatePrice(hasWhippedCream, hasChocolate);

    // Display the order summary on the screen
    String message = createOrderSummary(name, price, hasWhippedCream, hasChocolate);

    // Use an intent to launch an email app.
    // Send the order summary in the email body.
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_SUBJECT,
            getString(R.string.order_summary_email_subject, name));
    intent.putExtra(Intent.EXTRA_TEXT, message);

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}
 
開發者ID:ItalianCoder,項目名稱:Google-Developer-Challenge-Scholarship-Android-Basics,代碼行數:36,代碼來源:MainActivity.java

示例3: domainFieldValid

import android.widget.EditText; //導入方法依賴的package包/類
public static boolean domainFieldValid(EditText view) {
    if (view.getText() != null) {
        String s = view.getText().toString();
        if (s.matches("^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)*[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?$") &&
            s.length() <= 253) {
            return true;
        }
        if (s.matches("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")) {
            return true;
        }
    }
    return false;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:14,代碼來源:Utility.java

示例4: getCommonEmoticonClickListener

import android.widget.EditText; //導入方法依賴的package包/類
public static EmoticonClickListener getCommonEmoticonClickListener(final EditText editText) {
        return new EmoticonClickListener() {
            @Override
            public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
                if (isDelBtn) {
                    PublishUtils.delClick(editText);
                } else {
                    if (o == null) {
                        return;
                    }
                    if (actionType == Constants.EMOTICON_CLICK_TEXT) {
                        String content = null;
//                        if (o instanceof EmojiBean) {
//                            content = ((EmojiBean) o).emoji;
//                        } else
                        if (o instanceof EmoticonEntity) {
                            content = ((EmoticonEntity) o).getContent();
                        }

                        if (TextUtils.isEmpty(content)) {
                            return;
                        }
                        int index = editText.getSelectionStart();
                        Editable editable = editText.getText();
                        editable.insert(index, content);
                    }
                }
            }
        };
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:PublishUtils.java

示例5: onCreate

import android.widget.EditText; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post_detail);

    // Get post key from intent
    mPostKey = getIntent().getStringExtra(EXTRA_POST_KEY);
    if (mPostKey == null) {
        throw new IllegalArgumentException("Must pass EXTRA_POST_KEY");
    }

    // Initialize Database
    mPostReference = FirebaseDatabase.getInstance().getReference()
            .child("posts").child(mPostKey);
    mCommentsReference = FirebaseDatabase.getInstance().getReference()
            .child("post-comments").child(mPostKey);

    // Initialize Views
    mAuthorView = (TextView) findViewById(R.id.post_author);
    mTitleView = (TextView) findViewById(R.id.post_title);
    mBodyView = (TextView) findViewById(R.id.post_body);
    mCommentField = (EditText) findViewById(R.id.field_comment_text);
    mCommentButton = (ImageButton) findViewById(R.id.button_post_comment);
    mCommentButton.setEnabled(false);
    if (mCommentField.getText() != null){
        mCommentButton.setEnabled(true);
        mCommentButton.setImageResource(R.drawable.ic_foursquare_button);
    }
    mCommentsRecycler = (RecyclerView) findViewById(R.id.recycler_comments);
    detailedPicture = (ImageView)findViewById(R.id.post_author_photo);
    mCommentButton.setOnClickListener(this);
    mCommentsRecycler.setLayoutManager(new LinearLayoutManager(this));
    authorImage = (ImageView)findViewById(R.id._author_photo);
    authorName = (TextView)findViewById(R.id.author_name);
    authorJob = (TextView)findViewById(R.id.author_job_title);
    aboutTheAuthor = (TextView)findViewById(R.id.author_description_);
    numberOfParticipants = (TextView)findViewById(R.id.number_of_participants);
    timeStampText = (TextView)findViewById(R.id.the_real_fucking_time);

}
 
開發者ID:braulio94,項目名稱:Quadro,代碼行數:41,代碼來源:PostDetailActivity.java

示例6: getTimeSpanFromDialog

import android.widget.EditText; //導入方法依賴的package包/類
public static TimeSpan getTimeSpanFromDialog(Context context, View dialog)
{
	EditText timeSpanEditText = (EditText) dialog.findViewById(R.id.timeSpanEditText);
	Spinner timeSpanSpinner = (Spinner) dialog.findViewById(R.id.timeSpanSpinner);

	if (timeSpanEditText == null || timeSpanSpinner == null)
	{
		return new TimeSpan(-1);
	}

	String timeSpanType = (String) timeSpanSpinner.getSelectedItem();

	Editable text = timeSpanEditText.getText();
	String timeSpanAmountString = null;

	if (text != null)
	{
		timeSpanAmountString = text.toString();
	}

	int timeSpanAmount = 0;

	if (timeSpanAmountString != null && !"".equals(timeSpanAmountString))
	{
		timeSpanAmount = Integer.parseInt(timeSpanAmountString);
	}

	return calculateTimeSpan(context, timeSpanType, timeSpanAmount);
}
 
開發者ID:ultrasonic,項目名稱:ultrasonic,代碼行數:30,代碼來源:TimeSpanPicker.java

示例7: getCommonEmoticonClickListener

import android.widget.EditText; //導入方法依賴的package包/類
public static EmoticonClickListener getCommonEmoticonClickListener(final EditText editText) {
    return new EmoticonClickListener() {
        @Override
        public void onEmoticonClick(Object o, int actionType, boolean isDelBtn) {
            if (isDelBtn) {
                delClick(editText);
            } else {
                if (o == null) {
                    return;
                }
                if (actionType == Constants.EMOTICON_CLICK_TEXT) {
                    String content = null;
                    if (o instanceof EmojiBean) {
                        content = ((EmojiBean) o).emoji;
                    } else if (o instanceof EmoticonEntity) {
                        content = ((EmoticonEntity) o).getContent();
                    }

                    if (TextUtils.isEmpty(content)) {
                        return;
                    }
                    int index = editText.getSelectionStart();
                    Editable editable = editText.getText();
                    editable.insert(index, content);
                }
            }
        }
    };
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:30,代碼來源:ExpressionCommonUtils.java

示例8: searchByMaterialName

import android.widget.EditText; //導入方法依賴的package包/類
public void searchByMaterialName(View view) {
    EditText editTextDensity = (EditText) findViewById(R.id.editTextDensity);
    EditText editTextEnergy = (EditText) findViewById(R.id.editTextEnergy);
    EditText editTextDistance = (EditText) findViewById(R.id.editTextEditDistance);
    TextView textViewResult = (TextView) findViewById(R.id.textViewIDCalcAttnResult);
    if(editTextEnergy.getText()==null || editTextDensity.getText()==null || editTextDistance.getText()==null){
        textViewResult.setText("Must enter a value first");
        return;
    }
    try {
        fEnergy = Double.parseDouble(editTextEnergy.getText().toString());
        fDensity = Double.parseDouble(editTextDensity.getText().toString());
        fDistance = Double.parseDouble(editTextDistance.getText().toString());
    }
    catch (NumberFormatException e){
        textViewResult.setText("Must enter a value first");
        return;
    }

    if(fEnergy>=0.001&&fEnergy<=20){
        int i;
        double fCoeffInterp = 0;
        for(i=0; i<fEnergyList.length; i++){
            if(fEnergy == fEnergyList[i]){
                fCoeffInterp = fCoeffList[i];
                break;
            }
            if(fEnergy<fEnergyList[i]){
                fCoeffInterp = fCoeffList[i-1] + (fEnergy-fEnergyList[i-1])*(fCoeffList[i]-fCoeffList[i-1])/(fEnergyList[i]-fEnergyList[i-1]);
                break;
            }
        }
        textViewResult.setText(Double.toString(Math.exp(-fCoeffInterp*fDensity*fDistance)*100));
    }
    else{
        textViewResult.setText("Invalid energy range (0.001 to 20)");
    }
}
 
開發者ID:JW1992,項目名稱:NISTGammaSearch,代碼行數:39,代碼來源:CalcAttenuationActivity.java

示例9: insertAtCursor

import android.widget.EditText; //導入方法依賴的package包/類
private static int insertAtCursor(EditTextSelectionState selectionState,
                                  CharSequence textToInsert) {
    EditText editText = selectionState.getEditText();
    Editable editable = editText.getText();
    int editableLen = editable.length();
    int selStart = selectionState.getSelectionStart();
    int selEnd = selectionState.getSelectionEnd();
    int start = (selStart >= 0) ? selStart : editableLen-1;
    int end = (selEnd >= 0) ? selEnd : editableLen-1;
    editable.replace(Math.min(start, end), Math.max(start, end),
            textToInsert, 0, textToInsert.length());
    return Math.min(start, end);
}
 
開發者ID:TryGhost,項目名稱:Ghost-Android,代碼行數:14,代碼來源:EditTextUtils.java

示例10: getString

import android.widget.EditText; //導入方法依賴的package包/類
/**
 * Get string from edittext
 *
 * @param e The edittext
 * @return the string from edittext, null in all other cases
 */
@Nullable
public static String getString(@Nullable EditText e) {
    if (e == null) {
        return null;
    }
    if (e.getText() == null) {
        return null;
    }
    return getString(e.getText().toString());
}
 
開發者ID:yajnesh,項目名稱:AndroidGeneralUtils,代碼行數:17,代碼來源:GenericUtil.java

示例11: onShareClick

import android.widget.EditText; //導入方法依賴的package包/類
public void onShareClick(View view) {
    EditText editText = (EditText) findViewById(R.id.edit_text);
    if (editText != null) {
        CharSequence shareContent = editText.getText();
        AppChooser.from(this).text(shareContent.toString()).excluded(mComponentNames).load();
    }
}
 
開發者ID:JulianAndroid,項目名稱:AppChooser,代碼行數:8,代碼來源:ShareActivity.java

示例12: onNextButtonClick

import android.widget.EditText; //導入方法依賴的package包/類
@ActionHandler(layoutResource = R.id.next_button)
public void onNextButtonClick(View v){
    EditText passwordEditText       = (EditText)findViewById(R.id.password);
    EditText passwordConfirm1       = (EditText)findViewById(R.id.password_confirm);
    EditText usernameEdit           = (EditText)findViewById(R.id.username_edittext);

    String errorMessageLength       = "password length should be greater than 3";
    String errorMessageMatch        = "password does not match";
    CharSequence sequence           = passwordEditText.getText();
    CharSequence sequenceConfirm    = passwordConfirm1.getText();

    if(usernameEdit.getText().toString().length()<1){
        usernameEdit.setError("Please give me your name");
        return;
    }
    mUserName=usernameEdit.getText().toString();
    if(isValidPassword(sequence)){
        if(sequence.toString().equals(sequenceConfirm.toString())) {
            mUserSecretDatabase=sequence.toString();
                Boolean permission=checkPermissions();
                if(permission){
                    new DatabaseSetupTask().execute();
                }

            }else{
                passwordConfirm1.setError(errorMessageMatch);
            }
        }else{
            passwordEditText.setError(errorMessageLength);
        }

}
 
開發者ID:mosamabinomar,項目名稱:RootPGPExplorer,代碼行數:33,代碼來源:InitActivity.java

示例13: isEmpty

import android.widget.EditText; //導入方法依賴的package包/類
public static boolean isEmpty(EditText value) {
  return value == null || value.getText() == null || TextUtils.isEmpty(value.getText().toString());
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:4,代碼來源:Util.java

示例14: validateNotEmpty

import android.widget.EditText; //導入方法依賴的package包/類
public static boolean validateNotEmpty(EditText textField) {
    return textField != null && textField.getText()!=null && !textField.getText().toString().isEmpty();
}
 
開發者ID:joaomneto,項目名稱:TitanCompanion,代碼行數:4,代碼來源:AdventureTools.java

示例15: PerformInputAfter

import android.widget.EditText; //導入方法依賴的package包/類
private PerformInputAfter(@NonNull EditText editText) {
    Check.CheckNull(editText, "EditText不能為空");
    editable = editText.getText();
    editText.addTextChangedListener(new Watcher());
}
 
開發者ID:weimin96,項目名稱:shareNote,代碼行數:6,代碼來源:PerformInputAfter.java


注:本文中的android.widget.EditText.getText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。