我真的很困惑如何使用手机号码来处理用户输入。我一直得到错误"不能应用于编辑文本"还有其他办法吗?
XML
<EditText
android:layout_width="200dp"
android:layout_height="40dp"
android:inputType="phone"
android:ems="10"
android:id="@+id/mobilnummer"
android:hint="Mobilnummer"
android:imeOptions="actionSend"
android:textColor="#000000"
android:background="#ffffffff"
android:phoneNumber="true"
android:layout_weight="0.80"
android:layout_marginLeft="20dp"
android:layout_gravity="center_horizontal" />
JAVA
EditText mobilnummer;
mobilnummer = (EditText) findViewById(R.id.mobilnummer);
mobilnummer.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
if (mobilnummer >= 8) FragmentedUser.SaveMobile(mobilnummer);
handled = true;
}
return handled;
}
});
解析代码/片段类
public static void SaveMobile(String mobilnummer) {
ParseObject fragmentedUser = new ParseObject("FragmentedUser");
fragmentedUser.put("mobile", mobilnummer);
fragmentedUser.saveEventually();
Log.i("Save Mobile", "SaveMobile");
}
在Parse中唯一显示的是:android.widget.EditText {236a90fe VFED..CL .F ...... 113,0-821,120#7f0c0059 app:id / mobilnummer}
答案 0 :(得分:3)
您需要做一些更改。请看看。
EditText mobilnummer;
mobilnummer = (EditText) findViewById(R.id.mobilnummer);
mobilnummer.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
if (mobilnummer.getText().toString().length() >= 8)
FragmentedUser.SaveMobile(mobilnummer.getText().toString());
handled = true;
}
return handled;
}
});