Reputation:
I want to show some help text(much like in a webpage when a field is focused a non-modal popup is shown about what to enter in the field).
I have used android:hint
attribute of EditText but that clips the text if it is long. Is there any built in or quick way of doing this?
Upvotes: 3
Views: 6452
Reputation: 3255
Add a TextView below your EditText that contains the hint. By default set it to be invisible.
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your hint message..."
/>
Now add a onFocusChangeListener to make the TextView visible / invisible:
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
tvHint.setVisibility(View.VISIBLE);
}else{
tvHint.setVisibility(View.INVISIBLE);
}
}
});
Upvotes: 6
Reputation: 132982
you can use Custom Toast massages or PopupWindow for non-modal popup like web see these likes help u creating custom Toast and popupwindow
http://www.mobilemancer.com/2011/01/08/popup-window-in-android/
and use OnFocusChangeListener
Listener for tracking when user clicked on EditView or when leavening focus
txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus)
//show Toast massages or PopupWindow here
}
});
Upvotes: 0
Reputation: 18592
Have a TextView
just below the EditText
. Implement the onFocusListener
of the edittext and when the edit text has focus set the textView visibility to View.VISIBLE which will display the help text. And when the edit text loses its focus make the textview invisible.
Upvotes: 0