編輯:關於Android編程
class myWatcher implements TextWatcher { int beforeTextLength = 0; int onTextLength = 0; boolean isChanged = false; int location = 0;// 記錄光標的位置 private char[] tempChar; private StringBuffer buffer = new StringBuffer(); int konggeNumberB = 0; @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub onTextLength = s.length(); buffer.append(s.toString()); if (onTextLength == beforeTextLength || onTextLength <= 3 || isChanged) { isChanged = false; return; } isChanged = true; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub beforeTextLength = s.length(); if (buffer.length() > 0) { buffer.delete(0, buffer.length()); } konggeNumberB = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == ' ') { konggeNumberB++; } } } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub if (isChanged) { location = etAccount.getSelectionEnd(); int index = 0; while (index < buffer.length()) { if (buffer.charAt(index) == ' ') { buffer.deleteCharAt(index); } else { index++; } } index = 0; int konggeNumberC = 0; while (index < buffer.length()) { if ((index == 4 || index == 9 || index == 14 || index == 19)) { buffer.insert(index, ' '); konggeNumberC++; } index++; } if (konggeNumberC > konggeNumberB) { location += (konggeNumberC - konggeNumberB); } tempChar = new char[buffer.length()]; buffer.getChars(0, buffer.length(), tempChar, 0); String str = buffer.toString(); if (location > str.length()) { location = str.length(); } else if (location < 0) { location = 0; } etAccount.setText(str); Editable etable = etAccount.getText(); Selection.setSelection(etable, location); isChanged = false; } } } //給edititex 添加這個watcher
有些在使用越獄工具的朋友反映,使用過程中會提示“沒有找到蘋果設備”,由於這個錯誤提醒導致越獄不能繼續進行。當遇到這種情況我們應該怎麼
Doze模式是Android6.0上新出的一種模式,是一種全新的、低能耗的狀態,在後台只有部分任務允許運行,其他都被強制停止。當用戶一段時間沒有使用手機的時候,Doze模
前言在Android中使用 MVP 來開發已經出來很久了,剛好Google又出了一系列的architecture samples,在此就整理一下對於MVP的認知和實踐總結
0、基礎回顧PropertyAnimation,屬性動畫,顧名思義就是利用對象的屬性變化形成動畫的效果。屬性動畫的類可以用Animator這個抽象類來表示,通常使用它的子