Android -- TextView与EditText 同步显示
方法一.利用View.OnKeyListener"同步"显示
Java代码
Java代码 import android.app.Activity; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.widget.EditText; import android.widget.TextView; public class TextWatcherDemo extends Activity implements TextWatcher{ /** Called when the activity is first created. */ private TextView myText; private EditText myEdit; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myText=(TextView)findViewById(R.id.text); myEdit=(EditText)findViewById(R.id.edit); myEdit.addTextChangedListener(this); } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub myText.setText(myEdit.getText()); } }