2014-01-28 47 views
0

我的應用程序有兩個功能,驗證用戶輸入的輸入。一個EditText只能是數字,一個只能是字母。不能有空格或特殊字符。我已經完成了數字,但我搜索沒有字母驗證。那麼有人可以教我如何循環EditText並確保每個字符都是字母表嗎? 編輯:我改變我的代碼在我afterTextChanged.when我按我的userTextInout中的字母或數字,我的應用程序崩潰 第二個是計算用戶採取的步驟或只是使用GPS距離。但是我的輸出一無所有。它什麼都沒顯示。我不確定它是否與模擬器有關。在我以前的應用程序中,當我點擊模擬器控件發送gps數據時,它不會發送大部分時間,在我點擊發送按鈕後重復點擊它就可以更新我的位置。android gps距離。 EditText字母表驗證

我聽說有一個新的位置API更準確,但與我的區別是什麼?在Google開發者頁面上沒有太多細節。

即使我計算了距離,我該如何顯示它? setText不會顯示很長。這是我第一次使用distanceBetween方法,所以我不熟悉它。

XML代碼

<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/textInput" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="58dp" 
    android:layout_marginTop="34dp" 
    android:ems="5" 
    android:maxLength="100" 
    android:inputType="textMultiLine" /> 


<EditText 
    android:id="@+id/numberInput" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textInput" 
    android:layout_below="@+id/textInput" 
    android:layout_marginTop="64dp" 
    android:ems="5" 
    android:inputType="number" 
    android:maxLength="3" /> 

<TextView 
    android:id="@+id/Distance" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/numberInput" 
    android:layout_marginLeft="37dp" 
    android:layout_marginTop="107dp" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/currentLat" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/Distance" 
    android:layout_below="@+id/Distance" 
    android:layout_marginTop="29dp" 
    android:text="TextView" /> 

<TextView 
    android:id="@+id/currentLon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/currentLat" 
    android:layout_below="@+id/currentLat" 
    android:layout_marginTop="29dp" 
    android:text="TextView" /> 

</RelativeLayout> 

主要的Java代碼

import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Context; 
import android.text.Editable; 
import android.text.TextWatcher; 
//import android.view.Menu; 
import android.widget.EditText; 
import android.widget.TextView; 

public class MainActivity extends Activity implements TextWatcher{ 

protected LocationManager locationManager; 
EditText userNumberInput; 
EditText userTextInput; 
TextView distanceText; 
TextView latitude; 
TextView longitude; 
double lat1,lon1,lat2,lon2; 
long dist; 
float[] result; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    userNumberInput=(EditText)findViewById(R.id.numberInput); 
    userNumberInput.addTextChangedListener(this); 
    userTextInput=(EditText)findViewById(R.id.textInput); 
    distanceText=(TextView)findViewById(R.id.Distance); 
    latitude=(TextView)findViewById(R.id.currentLat); 
    longitude=(TextView)findViewById(R.id.currentLon); 
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); 


    Location loc1=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 

    Criteria criteria = new Criteria(); 

    //Get the name of the best provider 
    String provider = locationManager.getBestProvider(criteria, true); 
    locationManager.requestLocationUpdates(provider, 0, 1, myLocationListener); 

    latitude.setText(ToString(loc1.getLatitude())); 
    longitude.setText(ToString(loc1.getLongitude())); 

    //locationManager.requestLocationUpdates(netprovider, 0, 1, myLocationListener); 

} 

private CharSequence ToString(double latitude2) { 
    // TODO Auto-generated method stub 
    return null; 
} 

LocationListener myLocationListener = new LocationListener() 
{ 
    public void onLocationChanged(Location loc2) 
    { 
     //Location loc2=new Location(""); 
     lat2=loc2.getLatitude(); 
     lon2=loc2.getLongitude(); 
     latitude.setText(ToString(loc2.getLatitude())); 
     longitude.setText(ToString(loc2.getLongitude())); 
     if(lat1 != 0 && lon1 != 0) { 
      Location.distanceBetween(lat1,lon1,lat2,lon2,result); 
      dist+=(long)result[0]; 
     } 
     lat1=lat2; 
     lon1=lon2; 
     lat2=loc2.getLatitude(); 
     lon2=loc2.getLongitude(); 


    distanceText.setText(lat1+","+lon1+","+lat2+","+lon2, dist); 




} 
private CharSequence ToString(double latitude) { 
     // TODO Auto-generated method stub 
     return null; 
    } 
public void onProviderDisabled(String provider) 
{ 
    // Update application if provider disabled. 
} 
public void onProviderEnabled(String provider) 
{ 
    // Update application if provider enabled. 
} 
public void onStatusChanged(String provider, int status, 
     Bundle extras) 
{ 
    // Update application if provider hardware status changed. 
} 
}; 




@Override 
public void afterTextChanged(Editable edit) { 
      String textFromEditView = edit.toString(); 
    try 
    { 
     boolean isOnlyAlphabet = textFromEditView.matches("/^[A-z]+$/"); 
     if(isOnlyAlphabet == false) 
     { 
      edit.replace(0, edit.length(), "only alphabets"); 
     } 
    } 
    catch(NumberFormatException e){} 


} 

@Override 
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, 
     int arg3) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { 
    // TODO Auto-generated method stub 

}} 

01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 70 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 70 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 70 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 70 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 70 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[2] is 41 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 77 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 77 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 65 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 77 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 65 
01-28 21:33:00.730: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[2] is 69 
01-28 21:33:00.740: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.740: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.740: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.740: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.765: D/libEGL(7383): loaded /system/lib/egl/libEGL_mali.so 
01-28 21:33:00.765: D/libEGL(7383): loaded /system/lib/egl/libGLESv1_CM_mali.so 
01-28 21:33:00.775: D/libEGL(7383): loaded /system/lib/egl/libGLESv2_mali.so 
01-28 21:33:00.780: D/(7383): Device driver API match 
01-28 21:33:00.780: D/(7383): Device driver API version: 10 
01-28 21:33:00.780: D/(7383): User space API version: 10 
01-28 21:33:00.780: D/(7383): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 
01-28 21:33:00.815: D/OpenGLRenderer(7383): Enabling debug mode 0 
01-28 21:33:00.815: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.815: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.820: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.820: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.825: E/SensorManager(7383): thread start 
01-28 21:33:00.825: D/SensorManager(7383): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= [email protected]4157f0 
01-28 21:33:00.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:00.865: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 70 
01-28 21:33:00.865: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 70 
01-28 21:33:00.865: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 70 
01-28 21:33:00.865: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 70 
01-28 21:33:00.865: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 70 
01-28 21:33:00.865: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[2] is 41 
01-28 21:33:00.870: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 77 
01-28 21:33:00.870: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 77 
01-28 21:33:00.870: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 65 
01-28 21:33:00.870: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[0] is 77 
01-28 21:33:00.870: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[1] is 65 
01-28 21:33:00.870: D/TextLayoutCache(7383): TextLayoutCache::replaceThai, prevBuffer[2] is 69 
01-28 21:33:01.040: D/SensorManager(7383): unregisterListener:: Listener= [email protected]4157f0 
01-28 21:33:01.040: D/Sensors(7383): Remain listener = Sending .. normal delay 200ms 
01-28 21:33:01.040: I/Sensors(7383): sendDelay --- 200000000 
01-28 21:33:01.045: D/SensorManager(7383): JNI - sendDelay 
01-28 21:33:01.045: I/SensorManager(7383): Set normal delay = true 
01-28 21:33:01.545: W/IInputConnectionWrapper(7383): showStatusIcon on inactive InputConnection 
01-28 21:33:10.460: E/SensorManager(7383): thread start 
01-28 21:33:10.465: D/SensorManager(7383): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= [email protected]4157f0 
01-28 21:33:12.555: D/SensorManager(7383): unregisterListener:: Listener= [email protected]4157f0 
01-28 21:33:12.555: D/Sensors(7383): Remain listener = Sending .. normal delay 200ms 
01-28 21:33:12.555: I/Sensors(7383): sendDelay --- 200000000 
01-28 21:33:12.555: D/SensorManager(7383): JNI - sendDelay 
01-28 21:33:12.555: I/SensorManager(7383): Set normal delay = true 
01-28 21:33:12.555: D/SensorManager(7383): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= [email protected]417a08 
01-28 21:33:12.565: W/IInputConnectionWrapper(7383): getSelectedText on inactive InputConnection 
01-28 21:33:12.565: W/IInputConnectionWrapper(7383): setComposingText on inactive InputConnection 
01-28 21:33:12.565: W/IInputConnectionWrapper(7383): getExtractedText on inactive InputConnection 
01-28 21:33:12.675: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:12.675: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:12.680: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:12.680: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.645: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.645: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.645: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:13.645: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.225: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.225: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.225: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.230: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.845: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.845: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.845: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:15.845: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:16.425: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:16.425: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:16.430: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:16.430: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:18.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:18.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:18.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:18.260: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.695: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.695: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.695: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.695: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.860: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.865: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.880: D/dalvikvm(7383): GC_CONCURRENT freed 233K, 7% free 12329K/13191K, paused 13ms+4ms, total 41ms 
01-28 21:33:19.995: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.995: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.995: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:19.995: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.245: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.245: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.245: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.245: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.395: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.395: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.395: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.400: E/Dynamiclayout(7383): java.lang.IndexOutOfBoundsException: charAt: 0 >= length 0 
01-28 21:33:20.995: D/AndroidRuntime(7383): Shutting down VM 
01-28 21:33:20.995: W/dalvikvm(7383): threadid=1: thread exiting with uncaught exception (group=0x4178f2a0) 
01-28 21:33:20.995: E/AndroidRuntime(7383): FATAL EXCEPTION: main 
01-28 21:33:20.995: E/AndroidRuntime(7383): java.lang.IllegalArgumentException: results is null or has length < 1 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.location.Location.distanceBetween(Location.java:394) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at com.example.validationapp.MainActivity$1.onLocationChanged(MainActivity.java:74) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:263) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:196) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:212) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.os.Looper.loop(Looper.java:137) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at android.app.ActivityThread.main(ActivityThread.java:4898) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at java.lang.reflect.Method.invoke(Method.java:511) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 
01-28 21:33:20.995: E/AndroidRuntime(7383):  at dalvik.system.NativeStart.main(Native Method) 
01-28 21:33:30.770: I/Process(7383): Sending signal. PID: 7383 SIG: 9 

回答

1

您可以用正則表達式驗證輸入。只要使用這個代碼(在這裏找到:Regular Expression to match only alphabetic characters):

boolean isOnlyAlphabet = userTextInput.matches("/^[A-z]+$/"); 

對於第二個問題,我也沒有辦法。抱歉。

+0

感謝您的幫助。當我粘貼代碼時,匹配「方法匹配(字符串)是未定義的類型EditText」在我投它後,它也出現錯誤。順便說一句,如果它的工作,我在哪裏粘貼它。在afterTextChanged? – Myst

+0

嘗試 \t \t { \t \t \t布爾isOnlyAlphabet = userTextInput.matches( 「/^[A-Z] + $ /」); \t \t \t如果(布爾假==) \t \t \t { \t \t \t \t edit.replace(0,edit.length(), 「僅字母」); \t \t \t} \t \t} \t \t趕上(NumberFormatException的E){}但afterTextChanged只允許處理一個的EditText? – Myst

+0

其。好的,我找到了解決方案。我使用android:digits =「qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM」。它給了我我想要的東西。感謝您的努力! – Myst