MaskedEditText 无法获取文本
MaskedEditText cannot get text
对不起我的英语。
我正在使用库 MaskedEditText。一切正常,但我可以获取文本(仅文本)。
示例:我有 XML:
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="@+id/phoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:background="@null"
android:inputType="number"
mask:mask="(###) ###-##-##"
>
</br.com.sapereaude.maskedEditText.MaskedEditText>
如果用户输入文本:(111) 111-11-11
,
我应该只得到 1111111111
.
下面是我的代码
MaskedEditText text = (MaskedEditText) findViewById(R.id.phoneNumber);
Toast.makeText(MainActivity.this, "Text without mask: " +
text.getText(true), Toast.LENGTH_LONG).show();
错误:The method getText() in the type EditText is not applicable for the arguments (boolean)
更新
如果我使用这些方法:
Log.e("Mask ", text.getMask());
Log.e("getCharRepresentation ",
String.valueOf(text.getCharRepresentation()));
Log.e("getCharRepresentation ", text.getText().toString());
它的输出:
05-30 12:41:40.448: E/Mask(7980): (###) ###-##-##
05-30 12:41:40.448: E/getCharRepresentation(7980): #
05-30 12:41:40.448: E/getCharRepresentation(7980): (111) 111-11-11
The error: The method getText() in the type EditText is not applicable for the arguments (boolean)
这表示方法 getText()
不能采用布尔值 (true
) 参数。
尝试不使用 true
。如果那也 returns 括号和内容检查由 MaskedEditText
添加的方法。
好的,假设您只有 (
、)
和 -
要删除..
String str = String.valueOf(text.getCharRepresentation());
str = str.replaceAll("\D", ""); // Replace all non-digits
这是一个例子:
public class TestReplacement {
public static void main (String [] args) {
String str = "(111) 111-11-11";
System.out.println("String before replacement: " + str);
str = str.replaceAll("\D", ""); // Replace all non-digits
System.out.println("String after replacement: " + str);
}
}
输出:
String before replacement: (111) 111-11-11
String after replacement: 1111111111
用于获取没有掩码和提示的文本,
EditText.getRawText()
对不起我的英语。
我正在使用库 MaskedEditText。一切正常,但我可以获取文本(仅文本)。
示例:我有 XML:
<br.com.sapereaude.maskedEditText.MaskedEditText
android:id="@+id/phoneNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:background="@null"
android:inputType="number"
mask:mask="(###) ###-##-##"
>
</br.com.sapereaude.maskedEditText.MaskedEditText>
如果用户输入文本:(111) 111-11-11
,
我应该只得到 1111111111
.
下面是我的代码
MaskedEditText text = (MaskedEditText) findViewById(R.id.phoneNumber);
Toast.makeText(MainActivity.this, "Text without mask: " +
text.getText(true), Toast.LENGTH_LONG).show();
错误:The method getText() in the type EditText is not applicable for the arguments (boolean)
更新
如果我使用这些方法:
Log.e("Mask ", text.getMask());
Log.e("getCharRepresentation ",
String.valueOf(text.getCharRepresentation()));
Log.e("getCharRepresentation ", text.getText().toString());
它的输出:
05-30 12:41:40.448: E/Mask(7980): (###) ###-##-##
05-30 12:41:40.448: E/getCharRepresentation(7980): #
05-30 12:41:40.448: E/getCharRepresentation(7980): (111) 111-11-11
The error:
The method getText() in the type EditText is not applicable for the arguments (boolean)
这表示方法 getText()
不能采用布尔值 (true
) 参数。
尝试不使用 true
。如果那也 returns 括号和内容检查由 MaskedEditText
添加的方法。
好的,假设您只有 (
、)
和 -
要删除..
String str = String.valueOf(text.getCharRepresentation());
str = str.replaceAll("\D", ""); // Replace all non-digits
这是一个例子:
public class TestReplacement {
public static void main (String [] args) {
String str = "(111) 111-11-11";
System.out.println("String before replacement: " + str);
str = str.replaceAll("\D", ""); // Replace all non-digits
System.out.println("String after replacement: " + str);
}
}
输出:
String before replacement: (111) 111-11-11
String after replacement: 1111111111
用于获取没有掩码和提示的文本,
EditText.getRawText()