android:digits="abc"
android:inputType="number"
String s=et_verify_empty.getText().toString();
if(s==null||s.length()==0){
et_verify_empty.setError("不能为空");
}
package fry;
import com.example.editTextDemo1.R;
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class ActivityDemo2 extends Activity implements OnClickListener{
private EditText et_verify_empty;
private Button btn_verify;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity02);
setTitle("EditText实现输入限制和校验");
et_verify_empty=(EditText) findViewById(R.id.et_verify_empty);
btn_verify=(Button) findViewById(R.id.btn_verify);
btn_verify.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String s=et_verify_empty.getText().toString();
//if(s==null||s.length()==0){
if(TextUtils.isEmpty(s)){
et_verify_empty.setError("不能为空");
}
}
}
<?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"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="通过android:digits限制只能输入小写abc"
/>
<EditText
android:id="@+id/et_limit_abc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abc"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="通过android:inputType限制只能输入数字"
/>
<!-- 在android:inputType中可以设置各种限制,比如邮箱地址等等 -->
<EditText
android:id="@+id/et_limit_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="通过代码校验EditText是否为空"
/>
<!-- 在android:inputType中可以设置各种限制,比如邮箱地址等等 -->
<EditText
android:id="@+id/et_verify_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType=""
/>
<Button
android:id="@+id/btn_verify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="开始校验"
/>
</LinearLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有