我在Android上看过一个应用程序,只要一个人在文本框中输入任何内容,另一个显示输出的文本框会自动更改而无需按任何按钮或任何内容。我想知道如何为Android应用程序做到这一点。
答案 0 :(得分:1)
您可以通过向EditText添加addTextChangedListener来完成此操作。对用户在afterTextChanged
中输入的数据执行所有操作,因为此方法在用户停止在Edittext中键入时调用
EditText edttext = (EditText)findViewById(R.id.edttext);
edttext.addTextChangedListener(textChecker);
TextWatcher textChecker = new TextWatcher() {
public void afterTextChanged(Editable s) {
//set text to other Views
}
};
请参阅this示例,了解我们如何使用TextWatcher
答案 1 :(得分:0)
您可以addTextChangedListener
使用EditText并使用onTextChanged
功能更改其他EditText中的文字。
答案 2 :(得分:0)
这里的ed是EditText,我想,这段代码完成了你的期望..只是试试这段代码
ed.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int end) {
// TODO Auto-generated method stub
//tv.setText(s.toString());
if(s.length()==1){
String get=s.toString();
tv.setText(s.toString());
tv.startAnimation(mytrans);
mytrans.reset();
}else if(s.length()==2){
tv1.setText(s.subSequence(1,2));
tv1.startAnimation(myanim);
}else if(s.length()==3){
tv2.setText(s.subSequence(2, 3));
tv2.startAnimation(mytrans);
}else if(s.length()==4){
tv3.setText(s.subSequence(3, 4));
tv3.startAnimation(myalpha);
}else if(s.length()==5){
tv4.setText(s.subSequence(4, 5));
tv4.startAnimation(myanim1);
}else{
tv.setText(s.toString());
ObjectAnimator animation2 = ObjectAnimator.ofFloat(tv,"translationX",180);
animation2.setDuration(2000);
animation2.start();
ObjectAnimator animation3 = ObjectAnimator.ofFloat(tv,"translationY",100);
animation3.setDuration(2000);
animation3.start();
ObjectAnimator animation4 = ObjectAnimator.ofFloat(tv,"rotation",360);
animation4.setDuration(2000);
animation4.start();
ib.startAnimation(myanim);
ib1.startAnimation(myanim1);
tv.startAnimation(mytrans);
}
/*if(s.length()==6){
ib.requestFocus();
}*/
}
@Override
public void beforeTextChanged(CharSequence s, int start, int end,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
/*ib.startAnimation(myanim);
ib1.startAnimation(myanim1);
tv.startAnimation(mytrans); */
}
});