Http://itindex.net/detail/38974-android-edittext-%E7%9B%91%E5%90%AC
Sometimes we may use the constant listening edittext input characters to listen, listen to the number of characters, do some regular expression processing and so on. The following methods can be implemented:
All I do is synchronize the Editetext input data to the TextView.
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>
Java code:
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";p rivate EditText medittext;private TextView mText View; @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 menu) {getmenuinflater (). Inflate (r.menu.activity_test02, menu); return true; } }
Input listening for Android edittext, dynamic acquisition of input characters