我做了一些研究,但找不到问题的答案。我的布局中有一个 EditText
和一个 TextView
。我想要完成的是,当我输入 EditText
时,它会直接进入我的 TextView
。我不知道这是否可能。谁能帮我解决我的问题?
提前致谢! :)
最佳答案
您必须在 onCreate
方法中为 Activity
实现一个 TextWatcher
。
EditText editBox = (EditText)findViewById(R.id.edit_box_id);
editBox.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s){
((TextView)findViewById(R.id.textview_id)).setText(s.toString());
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
请务必将 R.id.edit_box_id
替换为实际的 EditText
字段 ID,将 R.id.textview_id
替换为实际的 TextView
id.
关于android - EditText直接到TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21783170/