init EditText By Type - Android User Interface

Android examples for User Interface:EditText

Description

init EditText By Type

Demo Code


//package com.java2s;

import android.text.InputType;
import android.widget.EditText;

public class Main {
    public static EditText initEditTextByType(EditText et, Class clazz) {
        if (clazz == Integer.class || clazz == Long.class) {
            et.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
        } else if (clazz == Float.class || clazz == Double.class) {
            et.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
        } else if (clazz == String.class) {
            et.setInputType(InputType.TYPE_CLASS_TEXT);
        } else {/*from w  ww .j  av  a2 s .c o m*/
            et.setInputType(InputType.TYPE_CLASS_TEXT);
        }
        return et;
    }
}

Related Tutorials