【发布时间】:2016-05-04 21:08:11
【问题描述】:
**`I want to develop an edit text which saprates the phone number
在 x-xxx-xxx-xxxx 这种格式中。确保我不想附加 - 在数之间。它应该看起来像四个不同的编辑文本和 进入每个块后,焦点会自动更改为下一个,例如 信用卡付款`。**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:inputType="number"
android:maxLength="15"
android:layout_marginBottom="5dp"/>
</RelativeLayout>
这里是相关的活动代码-
test.addTextChangedListener(new TextWatcher() {
private boolean mFormatting;
private int mAfter;
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (!mFormatting) {
mFormatting = true;
}
if(mAfter!=0)
PhoneNumberUtils.formatNumber(s,PhoneNumberUtils.getFormatTypeForLocale(Locale.US));
mFormatting = false;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
mAfter = after;
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
});
【问题讨论】:
-
用您项目中的代码示例更新您的答案。尝试包含演示您的特定问题所需的最少代码。
-
另外,您的问题确实很广泛。您应该专注于将问题进一步分解为更小的功能,例如:“在输入不同的文本视图后如何聚焦文本视图”
标签: android