Method to get a EditText with hint - Android User Interface

Android examples for User Interface:EditText

Description

Method to get a EditText with hint

Demo Code


import android.content.Context;
import android.text.InputFilter;
import android.widget.EditText;

public class Main {
  /**/* ww w. ja v  a2s  .  c  o  m*/
   * Method to get a EditText with hint
   * 
   * @param context
   *          Context
   * @param hint
   *          Hint to be displayed
   * @param maxLength
   *          Max input allowed for the EditText
   * @return EditText
   */
  public static EditText getEditTextWithHint(Context context, String hint,
      int maxLength) {
    final EditText mEditText = new EditText(context);
    mEditText.setHint(hint);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
        maxLength) });
    return mEditText;
  }
}

Related Tutorials