0

How show hint text when open edittext in fullscreen mode? I'm can show hint text with OnFocusChangeListener.

 editChangeName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            editChangeName.setHint(b ? getResources().getString(R.string.name) : "");
        }
    });

But.

How hide hint text after closing edittext?

  • I've provided an answer to this in this question (this is a duplicate, but I don't want to flag because it already has a (different) accepted answer). https://stackoverflow.com/a/52975488/3238938 – Damien Diehl Oct 24 '18 at 18:12

1 Answers1

0
   // assuming you have a EditText view with id 
   View viewById = getView().findViewById(R.id.editTextId);
   if(viewById!=null) {
           //  set listener to this view "many views could share one listener"
           viewById.setOnFocusChangeListener(new View.OnFocusChangeListener() {
               @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    // if view match id &&  has no focus 
                    if(v.getId() == R.id.editTextId && !hasFocus) 
                             // clear hint 
                             ((EditText) v).setHint(null);
                    // else show hint 
                }
          });
   }

hasFocus <- as name says

  • has (true) -> show
  • doesn't have (false) -> hide

if you are not sure if view by id is one you assign to an edit text do a check ( double check will not hurt)

  if (EditText.class.isAssignableFrom(v.getClass()))
     // do cast  
     EditText editText = (EditText) v;

This code is correct. But. How hide hinttext, after closing softkeyboard.. edittext have focus – Eugenu Yansky

Detecting when user has dismissed the soft keyboard

How to remove focus without setting focus to another control?

How to clear focus and remove keyboard on Android?

Community
  • 1
  • 1
ceph3us
  • 7,326
  • 3
  • 36
  • 43