2011-09-13 102 views

回答

8
String last = yourEditText.getText().toString(); 
last = last.substring(last.length() - 1); 

System.out.println("last character: " + last); 
0

因爲getText()返回CharSequence你也可以使用,用來獲取最後一個字符:

EditText my; 
my = (EditText) findViewById(R.id.editText1); 
CharSequence myCharSeq = my.getText(); 
System.out.println(myCharSeq.charAt(myCharSeq.length() - 1)); 
1

擴大DonGru的帖子,與得到的最後一個字符

EditText et; 
et = (EditText) findViewById(R.id.et); 
CharSequence s = et.getText(); 
System.out.println(s.subSequence(s.length()-1, s.length())); 
的另一種選擇
相關問題