检查自定义视图的输入类型
Check input type of Custom View
我的问题是关于 Android/Java。
如何在不创建 attr.xml 的情况下检查自定义视图的输入类型?
我的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:inputType="textEmailAddress"
android:layout_height="wrap_content"
android:ems="10"/>
<org.javaforum.input
android:layout_width="wrap_content"
android:inputType="textEmailAddress"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter your E-Mail"
/>
</LinearLayout>
我的input.java:
import android.widget.*;
import android.content.*;
import android.util.*;
import android.view.*;
import android.view.LayoutInflater.*;
import android.content.res.*;
public class input extends TextView{
public input(Context context, AttributeSet attr) {
//How can check if input type are textEmailAddress?
super(context,attr);
}
@Override
public void onFinishInflate() {
// this is the right point to do some things with View objects,
// as example childs of THIS View object
}
}
所以我想知道我的自定义视图的输入类型是否设置为“textEmailAddress”。我该怎么做?
只要你从TextView
继承你的class,你可以使用getInputType()
方法,它会return一个整数值,你可以检查它是否是等于TYPE_TEXT_VARIATION_EMAIL_ADDRESS
public boolean isTextEmailAddress() {
return getInputType() == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
}
我的问题是关于 Android/Java。
如何在不创建 attr.xml 的情况下检查自定义视图的输入类型?
我的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:inputType="textEmailAddress"
android:layout_height="wrap_content"
android:ems="10"/>
<org.javaforum.input
android:layout_width="wrap_content"
android:inputType="textEmailAddress"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter your E-Mail"
/>
</LinearLayout>
我的input.java:
import android.widget.*;
import android.content.*;
import android.util.*;
import android.view.*;
import android.view.LayoutInflater.*;
import android.content.res.*;
public class input extends TextView{
public input(Context context, AttributeSet attr) {
//How can check if input type are textEmailAddress?
super(context,attr);
}
@Override
public void onFinishInflate() {
// this is the right point to do some things with View objects,
// as example childs of THIS View object
}
}
所以我想知道我的自定义视图的输入类型是否设置为“textEmailAddress”。我该怎么做?
只要你从TextView
继承你的class,你可以使用getInputType()
方法,它会return一个整数值,你可以检查它是否是等于TYPE_TEXT_VARIATION_EMAIL_ADDRESS
public boolean isTextEmailAddress() {
return getInputType() == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
}