MACMAN
MACMAN

Reputation: 1971

How To Establish A Relation Between An EditText and TextView in Android?

Is there anyway to establish a relationship between an edittext and textview that is inside a table row? The purpose is to change the color of textview while the edittext is clicked. Some kind of parent child relationship is possible? Any clue? Thanks.

Upvotes: 0

Views: 51

Answers (2)

Deep Patel
Deep Patel

Reputation: 2644

Try this, when EditText will be in focus TextView color will get changed, and on focusing other view color will get changed again.

 editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean isFocused) {
                textView.setTextColor(isFocused ? ContextCompat.getColor(this, R.color.bg_red) : ContextCompat.getColor(R.color.bg_blue));
            }
        });

Upvotes: 1

Bhagat
Bhagat

Reputation: 80

You can either use onClickListener or addTextWatcher on Edittext to achieve required behavior.

Upvotes: 1

Related Questions