EditText with a permanent hint in Java


I have an EditText with some information in it. When there is no information, I'm displaying a caption using setHint().

final EditText info = new EditText(activity); if (data.getinfo() != null && !data.getAddress().trim().equals("")) { info.setText(data.getinfo()); } else { info.setHint(R.string.info); }

I want to show that caption even if the EditText has info, the info should be below the caption.

I tried using setText(). But that didn't work either.

if (condition) { info.setText(R.string.info); info.setText(data.getinfo()); } else { info.setHint(R.string.info); }


Within a RelativeLayout, use a TextView as an overlay View on top of your EditText. Use appropriate colors, size for the font to achieve the effect you are looking for.

Here is a hint

<RelativeLayout …> <EditText android:id="@+id/name" android:layoutWidth="match_parent" android:layoutHeight="wrap_content" > <TextView android:id="@+id/name_hint" android:layoutWidth="wrap_content" android:layoutHeight="wrap_content" android:gravity="left|center_vertical" android:layout_alignLeft="@id/name" android:layout_alignRight="@id/name" android:layout_alignTop="@id/name" android:layout_alignBottom="@id/name" android:layout_alignBottom="@id/name" > </RelativeLayout>

This is just a starting point, you can adjust the height of your EditText, position your TextView, change its gravity, etc., to achieve what you are looking for.


You can directly do it through xml tag which you've added in your UI layout.


  • Flash screen Android
  • Why Android Studio creates two xml layout files
  • How do I make an EditText raise along with the keyboard when in focus?
  • Textview values does not update when data received from Arduino
  • Overlapping ImageView in RelativeView
  • Why is this code not working? Hangman
  • Why does .addView throw this parent/child exception?
  • How to Handle Click on Imageview in Custom Listview with image and Textview?
  • UIScrollView setContentOffset: animated: not working
  • Null ImageView Reference
  • EntLib Way to Bind “Null” Value to Parameter
  • Django model inheritance, filtering models
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • How to write order and limit within cakephp joins array
  • Highlight and Bold text in JTextPane
  • Change multiple background-images with jQuery
  • Xamarin Forms - UWP Fonts
  • QLineEdit password safety
  • Android screen density dpi vs ppi
  • Is possible to count alias result on mysql
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Sending data from AppleScript to FileMaker records
  • MySQL WHERE-condition in procedure ignored
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Change an a tag attribute in JavaScript based on screen width
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Unanticipated behavior
  • Cannot Parse HTML Data Using Android / JSOUP
  • Comma separated Values
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Benchmarking RAM performance - UWP and C#
  • Load html files in TinyMce
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • How to load view controller without button in storyboard?