1

私は EditText を持っており、ユーザーがこの editText に入力する文字ごとに、EditText のテキスト全体に関数を適用したいと考えていますFarsi class。ユーザーが 21 を入力したい場合の簡単な例を示します。関数を適用したいoutput=3*editText.getText(); ので、1 を入力すると関数が適用され、editText に表示される結果は次のようになります。

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
4

4 に答える 4

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){}
}); 
于 2012-06-30T14:08:11.527 に答える
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)
        {}
        } 
    });
于 2012-06-30T14:10:00.790 に答える
1
fileNameEditText.setOnKeyListener(new View.OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        return false;
    }
});

ビューのキー リスナーを設定します。

于 2012-06-30T14:07:32.933 に答える
1

これを確認してください: TextView.OnEditorActionListener editText.setOnEditorActionListener(yourListener)

編集:ああ、私は速く答えていました。もちろん、 TextWatcher を使用するという答えは正しい方法です。

于 2012-06-30T14:10:26.723 に答える