Method to get a EditText with text - Android User Interface

Android examples for User Interface:EditText

Description

Method to get a EditText with text

Demo Code


import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.InputFilter;
import android.text.util.Linkify;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Main{
    /**//from  w w  w . j  av a  2s  .c  om
     * Method to get a EditText with text
     * @param context   Context
     * @param text      Text to be displayed initially
     * @param maxLength Max input allowed for the EditText
     * @return EditText
     */
    public static EditText getEditTextWithText(Context context,
            String text, int maxLength) {
        final EditText mEditText = new EditText(context);
        mEditText.setText(text);
        mEditText
                .setFilters(new InputFilter[] { new InputFilter.LengthFilter(
                        maxLength) });
        return mEditText;
    }
}

Related Tutorials