【问题标题】:Get the String value of the EditText which has inputType numberPassword获取具有 inputType numberPassword 的 EditText 的 String 值
【发布时间】:2018-01-24 13:58:55
【问题描述】:

我想获取具有inputType 属性的EditTextString 值:numberPassword,我该怎么做?

Code_pin.getText().ToString() 始终返回 null 值。

【问题讨论】:

  • 先显示你的代码...

标签: android android-edittext passwords android-inputtype


【解决方案1】:
String str = null;

str = your_edit.getText().toString().trim(); //put your editText value in string

if (!TextUtils.isEmpty(str)) //check for empty
{
    // Do your task here
}

【讨论】:

    【解决方案2】:

    首先你必须得到EditTextId

    EditText et_pwd = (EditText) findViewById(R.id.et_pwd);         
    

    您的xml 文件:

    <EditText
        android:id="@+id/et_pwd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberPassword" />
    

    然后你调用getText()方法:

    String text = et_pwd.getText().toString().trim();
    if (text.equalsIgnoreCase("")) {
         // empty/blank string
    }else {
         // not blank string
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 2013-09-29
      相关资源
      最近更新 更多