Ad

Textview Content That Leads To An Automatic Action

- 1 answer

I am using a source code of a Speech-To-Text app (using Google Voice).

I would like to add a code that does the following:

Whenever the content of a TextView shows value X, it leads to an automatic action. And whenever it displays value Y, it leads to a different action.

For instance, the TextView content is read aloud, or the background colour is changed, etc. Not a setOnClickListener, but an automatic action. Thanks in advance!

Ad

Answer

That's so simple check this out:

editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        String text = charSequence.toString();
        if(text.equalsIgnoreCase("Y")){
            //Do your action
        }else if(text.equalsIgnoreCase("N")){
            //Do your action
        }
    }

    @Override
    public void afterTextChanged(Editable editable) {

    }
});
Ad
source: stackoverflow.com
Ad