Android edittext input listening, dynamic acquisition of input characters

Source: Internet
Author: User

Sometimes we may use the constant listening for the edittext input characters, the number of listening characters, and some regular expression processing. The following methods can be implemented:

What I do is synchronize the data input by editetext to textview from time to time.

Layout file:

<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"> <textview Android: id = "@ + ID/textview" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_centerhorizontal = "true" Android: layout_centervertical = "true" Android: padding = "@ dimen/padding_medium" tools: context = ". test02activity "/> <edittext Android: Id =" @ + ID/edittext1 "Android: layout_width =" fill_parent "Android: layout_height =" wrap_content "Android: layout_alignleft = "@ + ID/textview" Android: layout_below = "@ + ID/textview" Android: layout_margintop = "31dp"> <requestfocus/> </edittext> </relativelayout>

JavaCode:

Package COM. example. testdemo; import android. OS. bundle; import android. app. activity; import android. util. log; import android. view. menu; import android. view. menuitem; import android. widget. edittext; import android. widget. textview; import android. support. v4.app. navutils; import android. text. editable; import android. text. textwatcher; public class test02activity extends activity {Private Static final string tag = "test"; private edittext medittext; private textview mtextview; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_test02); medittext = (edittext) findviewbyid (R. id. edittext1); mtextview = (textview) findviewbyid (R. id. textview); medittext. addtextchangedlistener (New textwatcher () {@ overridepublic void aftertextchanged (editable s) {log. D (TAG, "aftertextchanged") ;}@ overridepublic void beforetextchanged (charsequence S, int start, int count, int after) {log. D (TAG, "beforetextchanged:" + S + "-" + start + "-" + Count + "-" + after) ;}@ overridepublic void ontextchanged (charsequence s, int start, int before, int count) {log. D (TAG, "ontextchanged:" + S + "-" + "-" + start + "-" + before + "-" + count); mtextview. settext (s) ;}}) ;}@ override public Boolean oncreateoptionsmenu (menu) {getmenuinflater (). inflate (R. menu. activity_test02, menu); Return true ;}}
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.