日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android edittext 手机号码,Android中EditText中的电话号码格式

發布時間:2025/3/15 Android 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android edittext 手机号码,Android中EditText中的电话号码格式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在Android的EditText中輸入電話號碼時,如何設置(xxx)xxx-xxxxx格式的電話號碼?

我想要(,),-字符自動添加到特定位置.

我寫了代碼,但僅在andorid 2.2版本中有效,而在上述版本中無效.

我在stackoverflow中搜索了更多問題.

請檢查我的代碼:

phone.addTextChangedListener(new TextWatcher () {

@Override

public void afterTextChanged(Editable chars) {

// TODO Auto-generated method stub

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

// TODO Auto-generated method stub

}

@Override

public void onTextChanged(final CharSequence s, final int start, int lengthBefore,

int lengthAfter) {

// TODO Auto-generated method stub

count = start;

/*if (phone.getText().length() <= 0) {

phone.append("(");

phone.setSelection(1);

}else if (count == 3) {

phone.append(")");

}else if (count == 7) {

phone.append("-");

}

*/

}

});

phone.setOnKeyListener(new OnKeyListener (){

@Override

public boolean onKey(View arg0, int arg1, KeyEvent arg2) {

// TODO Auto-generated method stub

if(arg1 == KeyEvent.KEYCODE_DEL){

if(count > 0){

count = count - 1;

}

}else{

if(phone.getText().length() <= 0){

phone.append("(");

}else{

if(count == 3){

phone.append(")");

}else if(count == 7){

phone.append("-");

}

}

}

return false;

}

});

}

Logcat顯示為:

01-03 15:07:23.529: W/InputManagerService(153): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40900f88

01-03 15:07:23.529: D/StatusBarPolicy(221): mFullChargeListener

01-03 15:07:25.749: V/AudioPolicyManager(84): startOutput() output 1, stream 1, session 1488

01-03 15:07:25.749: V/AudioPolicyManager(84): changeRefCount() stream 1, count 1

01-03 15:07:25.749: V/AudioPolicyManager(84): getDeviceForStrategy() from cache strategy 0, device 2

01-03 15:07:25.749: V/AudioPolicyManager(84): getNewDevice() selected device 2

01-03 15:07:25.749: V/AudioPolicyManager(84): setOutputDevice() output 1 device 2 delayMs 0

01-03 15:07:25.749: V/AudioPolicyManager(84): setOutputDevice() setting same device 2 or null device for output 1

01-03 15:07:25.749: V/AudioPolicyManager(84): releaseOutput() 1

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): open driver

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): get config

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): set config

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): buffer_size: 4800

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): buffer_count: 2

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): channel_count: 2

01-03 15:07:25.769: V/AudioHardwareMSM72XX(84): sample_rate: 44100

01-03 15:07:25.939: W/AudioFlinger(84): write blocked for 164 msecs, 61 delayed writes, thread 0xcdd0

01-03 15:07:26.009: V/AudioPolicyManager(84): stopOutput() output 1, stream 1, session 1488

01-03 15:07:26.009: V/AudioPolicyManager(84): changeRefCount() stream 1, count 0

01-03 15:07:26.009: V/AudioPolicyManager(84): getNewDevice() selected device 0

01-03 15:07:26.009: V/AudioPolicyManager(84): setOutputDevice() output 1 device 0 delayMs 0

01-03 15:07:26.009: V/AudioPolicyManager(84): setOutputDevice() setting same device 0 or null device for output 1

01-03 15:07:26.699: V/AudioPolicyManager(84): startOutput() output 1, stream 1, session 1489

01-03 15:07:26.699: V/AudioPolicyManager(84): changeRefCount() stream 1, count 1

01-03 15:07:26.699: V/AudioPolicyManager(84): getDeviceForStrategy() from cache strategy 0, device 2

01-03 15:07:26.699: V/AudioPolicyManager(84): getNewDevice() selected device 2

01-03 15:07:26.699: V/AudioPolicyManager(84): setOutputDevice() output 1 device 2 delayMs 0

01-03 15:07:26.699: V/AudioPolicyManager(84): setOutputDevice() setting same device 2 or null device for output 1

01-03 15:07:26.699: V/AudioPolicyManager(84): releaseOutput() 1

01-03 15:07:26.859: V/AudioPolicyManager(84): stopOutput() output 1, stream 1, session 1489

01-03 15:07:26.859: V/AudioPolicyManager(84): changeRefCount() stream 1, count 0

01-03 15:07:26.859: V/AudioPolicyManager(84): getNewDevice() selected device 0

01-03 15:07:26.859: V/AudioPolicyManager(84): setOutputDevice() output 1 device 0 delayMs 0

01-03 15:07:26.859: V/AudioPolicyManager(84): setOutputDevice() setting same device 0 or null device for output 1

01-03 15:07:27.499: I/StatusBarPolicy(221): BAT. status:5 health:2

總結

以上是生活随笔為你收集整理的android edittext 手机号码,Android中EditText中的电话号码格式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。