Skip to content Skip to sidebar Skip to footer

Edittext With An Helpper Tooltip

I have this app on iphone and I want to make it for android,on iphone when start edit text in a EditText a tooltip with a message is showing in the top of display,i want to make it

Solution 1:

There isin't a hovering tooltip concept in Android. You can do either of the 2 things:

LongClickListener for your EditText which will show a toast when user long presses on it. Something like this:

Viewview= (View)findViewById(R.id.your_view);
view.setOnLongClickListener(newOnLongClickListener() {
    @OverridepublicvoidonLongClick(View v) {
      Toasttoast= Toast.makeText(this, "Show hint here", Toast.LENGTH_SHORT);
    }
});

OR

Show Hint in the EditText to let users know what do they need to type in.

<EditTextandroid:hint="Your tip here" />

Solution 2:

@Override
    public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
        //your code here//showtooltip();
    }

    @Override
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
            int arg3) {
        // TODO Auto-generated method stub

    }

    @Override
    public void afterTextChanged(Editable arg0) {
        // TODO Auto-generated method stub
    }
});

}

Solution 3:

This can be done using OnFocusChangeListener on EditText

The idea is that you will create tool tip layout and will change its visibility on Focus change

You can create tip layout by either top of normal layout using FrameLayout or by just adding tool tip layout at top of your layout. In both these cases visibility will be gone.

Then use OnFocusChangeListener to show or hide tool tip

edittxt.setOnFocusChangeListener(newOnFocusChangeListener()
{
    @OverridepublicvoidonFocusChange(View v, boolean hasFocus) 
    {
        if (hasFocus == true)
        {
          // Show tool tip  
        }else{
           // Hide tool tip
        }
    }
});

You can also enhance this with different listeners like OnKeyListener

Just to improve my answer

you can also use TextWatcher Class of Android which facilitates us to react on Text Change.

Please refer following for use of TextWatcher in your example

TextWatchertextWatcher=newTextWatcher()
 {
    @OverridepublicvoidonTextChanged(CharSequence s , int start,int before,int count){

    }
    @OverridepublicvoidafterTextChanged(Editable s){

    }
    @OverridepublicvoidbeforeTextChanged(CharSequence s, int start,int count, int after){

    }

  };

   Then use it as 
   edittext.addTextChangedListener(textWatcher);

Solution 4:

You can use this: TooltipCompat.setTooltipText(editText, editText.getText())

Post a Comment for "Edittext With An Helpper Tooltip"