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:
[Html]
<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:
[Html]
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 (){
@ Override
Public void afterTextChanged (Editable s ){
Log. d (TAG, "afterTextChanged ");
}
@ Override
Public void beforeTextChanged (CharSequence s, int start, int count,
Int after ){
Log. d (TAG, "beforeTextChanged:" + s + "-" + start + "-" + count + "-" + after );
}
@ Override
Public 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;
}
}
Author: com360