Create new Text Input Field and return EditText - Android User Interface

Android examples for User Interface:EditText

Description

Create new Text Input Field and return EditText

Demo Code


import android.content.Context;
import android.graphics.Typeface;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import java.util.concurrent.atomic.AtomicInteger;

public class Main{
    public static EditText newTextInputField(Context context,
            int inputType, int hintStringId) {
        return newTextInputField(context, inputType,
                context.getString(hintStringId));
    }//from w ww .ja  v a2s .  com
    public static EditText newTextInputField(Context context,
            int inputType, String hint) {
        EditText editText = new EditText(context);
        editText.setInputType(inputType);
        int passwordFlags = EditorInfo.TYPE_TEXT_VARIATION_PASSWORD
                | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD;
        if ((inputType & passwordFlags) != 0) {
            editText.setTypeface(Typeface.DEFAULT);
        }
        if (hint != null && hint.length() > 0) {
            editText.setHint(hint);
        }
        return editText;
    }
}

Related Tutorials