我有一个EditText,并且对于每个lettle用户输入这个editText我想在EditText中对整个文本应用一个函数,那个函数是因为我用阿拉伯语写的并且阿拉伯语的lettle看起来不好,但是当我使用Farsi class
它变好了,如果用户想要输入21,我会给你一个简单的例子,我想应用函数output=3*editText.getText();
因此,当他输入1时,我将应用该函数,因此将出现在editText上的resutl是:
output = 3*1 = 3
当他输入2时,我想显示12*3 = 36
编辑
06-30 12:30:38.547: E/AndroidRuntime(276): FATAL EXCEPTION: main
06-30 12:30:38.547: E/AndroidRuntime(276): java.lang.StackOverflowError
06-30 12:30:38.547: E/AndroidRuntime(276): at android.text.DynamicLayout.reflow(DynamicLayout.java:261)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.text.DynamicLayout.<init>(DynamicLayout.java:150)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.makeNewLayout(TextView.java:4851)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.checkForRelayout(TextView.java:5348)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2688)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChanged(TextView.java:6131)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2691)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2556)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.EditText.setText(EditText.java:75)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.setText(TextView.java:2531)
06-30 12:30:38.547: E/AndroidRuntime(276): at com.localizedbasedcompetition.AnswerQuestion$3.onTextChanged(AnswerQuestion.java:149)
06-30 12:30:38.547: E/AndroidRuntime(276): at android.widget.TextView.sendOnTextChang
答案 0 :(得分:3)
您必须使用addTextChangedListener()和TextWatcher,如下所示:
tv = (TextView) findViewById(R.id.tv);
textMessage = (EditText) findViewById(R.id.tvMessage);
textMessage.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
//do your function here
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){}
});
答案 1 :(得分:2)
EditText editText = (EditText)findViewById(R.id.editText);
editText.addTextChangedListener(new TextWatcher() {
@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) {
try
{
String s1 = editText.Text.ToString();
byte[] b = s.getBytes("UTF-8");
String s2 = new String(b, "UTF-8");
editText.Text=(s2);
}
catch(Exception e)
{}
}
});
答案 2 :(得分:1)
fileNameEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
return false;
}
});
为您的视图设置一个关键监听器。
答案 3 :(得分:1)
检查一下:TextView.OnEditorActionListener editText.setOnEditorActionListener(yourListener)
编辑:哦,我正在快速回答。当然,使用TextWatcher的答案是正确的方法。