-
為了實現像qq或者微信輸入框的效果,當在
- EditText editText = (EditText)findViewById(R.id.monitor_edit_text0);
- editText.addTextChangedListener(new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence text, int start, int before, int count) {
- //text 輸入框中改變后的字符串信息
- //start 輸入框中改變后的字符串的起始位置
- //before 輸入框中改變前的字符串的位置 默認為0
- //count 輸入框中改變后的一共輸入字符串的數量
- textView1.setText("輸入后字符串 [ " + text.toString() + " ] 起始光標 [ " + start + " ] 輸入數量 [ " + count+" ]");
- }
- @Override
- public void beforeTextChanged(CharSequence text, int start, int count,int after) {
- //text 輸入框中改變前的字符串信息
- //start 輸入框中改變前的字符串的起始位置
- //count 輸入框中改變前后的字符串改變數量一般為0
- //after 輸入框中改變后的字符串與起始位置的偏移量
- System.out.println(text.toString());
- textView0.setText("輸入前字符串 [ " + text.toString() + " ]起始光標 [ " + start + " ]結束偏移量 [" + after + " ]");
- }
- @Override
- public void afterTextChanged(Editable edit) {
- //edit 輸入結束呈現在輸入框中的信息
- textView2.setText("輸入結束后的內容為 [" + edit.toString()+" ] 即將顯示在屏幕上");
- }
- });