0

I'm doing a app which has two EditText. What I want to do is, if you click on one and write on it, the other must erase anything it has and only shows the hint string. I'm trying doing it with a a check method that does:

if(celsius.isFocused()){
        
        faren.setText(faren.getHint().toString());
    }
    if(faren.isFocused()){
        
        celsius.setText(celsius.getHint().toString());
    }    

Then I call this method within the onCreate() method, but of course It only checks one time, and if use that checkMethod inside a loop, the app doesn't show anything, It freezes. An suggestions?

1 Answer 1

1

Use the OnFocusChangeListener.

faren.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if(hasFocus)
            celcius.setText(""); // This will automatically show the hint text
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.