一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Android - Android編程開發之EditText中不輸入特定字符會顯示相關提示信息的方法

Android編程開發之EditText中不輸入特定字符會顯示相關提示信息的方法

2021-04-26 17:44sgx425021234 Android

這篇文章主要介紹了Android編程開發之EditText中不輸入特定字符會顯示相關提示信息的方法,涉及Android針對EditText的布局操作及內容判定相關技巧,需要的朋友可以參考下

本文實例講述了android編程開發之edittext中不輸入特定字符會顯示相關提示信息的方法。分享給大家供大家參考,具體如下:

先看效果圖:

Android編程開發之EditText中不輸入特定字符會顯示相關提示信息的方法

源碼如下:

布局文件:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingbottom="@dimen/activity_vertical_margin"
  android:paddingleft="@dimen/activity_horizontal_margin"
  android:paddingright="@dimen/activity_horizontal_margin"
  android:paddingtop="@dimen/activity_vertical_margin"
  tools:context=".mainactivity" >
  <textview
    android:id="@+id/textview1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignparentleft="true"
    android:layout_alignparenttop="true"
    android:text="@string/text_num" />
  <textview
    android:id="@+id/textview2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignparentleft="true"
    android:layout_below="@+id/num"
    android:text="@string/text_abc" />
  <edittext
    android:id="@+id/num"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textview1"
    android:digits="0123456789"
    android:ems="10" />
  <edittext
    android:id="@+id/abc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignleft="@+id/textview2"
    android:layout_below="@+id/textview2"
    android:digits="qwertyuiopasdfghjklzxcvbnm"
    android:ems="10" >
  </edittext>
  <textview
    android:id="@+id/textview3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignleft="@+id/abc"
    android:layout_below="@+id/abc"
    android:layout_margintop="14dp"
    android:text="@string/text_num2" />
  <edittext
    android:id="@+id/num2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignleft="@+id/textview3"
    android:layout_below="@+id/textview3"
    android:ems="10"
    android:inputtype="number|textcapcharacters" >
  </edittext>
  <button
    android:id="@+id/button1"
    style="?android:attr/buttonstylesmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textview2"
    android:layout_below="@+id/textview1"
    android:layout_torightof="@+id/num"
    android:text="確認1" />
  <button
    android:id="@+id/button4"
    style="?android:attr/buttonstylesmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignbottom="@+id/email"
    android:layout_aligntop="@+id/email"
    android:layout_torightof="@+id/email"
    android:text="確認4" />
  <button
    android:id="@+id/button2"
    style="?android:attr/buttonstylesmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textview3"
    android:layout_alignleft="@+id/button1"
    android:layout_below="@+id/textview2"
    android:text="確認2" />
  <button
    android:id="@+id/button3"
    style="?android:attr/buttonstylesmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignbottom="@+id/num2"
    android:layout_alignleft="@+id/button2"
    android:layout_aligntop="@+id/num2"
    android:text="確認3" />
  <textview
    android:id="@+id/textview4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignparentleft="true"
    android:layout_centervertical="true"
    android:text="@string/text_email" />
  <edittext
    android:id="@+id/email"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignleft="@+id/textview4"
    android:layout_below="@+id/textview4"
    android:layout_margintop="21dp"
    android:ems="10"
    android:inputtype="textemailaddress" >
  </edittext>
</relativelayout>

mainactivity.java:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.example.edittext2;
import android.app.activity;
import android.os.bundle;
import android.view.menu;
import android.view.view;
import android.widget.button;
import android.widget.edittext;
public class mainactivity extends activity {
  private edittext num;
  private edittext abc;
  private edittext num2;
  private edittext email;
  private button button1;
  private button button2;
  private button button3;
  private button button4;
  @override
  protected void oncreate(bundle savedinstancestate) {
    super.oncreate(savedinstancestate);
    setcontentview(r.layout.activity_main);
    num=(edittext) findviewbyid(r.id.num);
    abc=(edittext) findviewbyid(r.id.abc);
    num2=(edittext) findviewbyid(r.id.num2);
    email=(edittext) findviewbyid(r.id.email);
    button1=(button) findviewbyid(r.id.button1);
    button2=(button) findviewbyid(r.id.button2);
    button3=(button) findviewbyid(r.id.button3);
    button4=(button) findviewbyid(r.id.button4);
    button1.setonclicklistener(new view.onclicklistener() {
      @override
      public void onclick(view v) {
        string value=num.gettext().tostring();
        //trim()判斷前后是否有空格
        if(value==null||value.trim().equals("")){
          num.seterror("請輸入內容!!");
          return;
        }
      }
    });
    button2.setonclicklistener(new view.onclicklistener() {
      @override
      public void onclick(view v) {
        string value=abc.gettext().tostring();
        //trim()判斷前后是否有空格
        if(value==null||value.trim().equals("")){
          abc.seterror("請輸入內容!!");
          return;
        }
      }
    });
    button3.setonclicklistener(new view.onclicklistener() {
      @override
      public void onclick(view v) {
        string value=num2.gettext().tostring();
        //trim()判斷前后是否有空格
        if(value==null||value.trim().equals("")){
          num2.seterror("請輸入內容!!");
          return;
        }
      }
    });
    button4.setonclicklistener(new view.onclicklistener() {
      @override
      public void onclick(view v) {
        string value=email.gettext().tostring();
        //trim()判斷前后是否有空格
        if(value==null||value.trim().equals("")){
          email.seterror("請輸入內容!!");
          return;
        }
      }
    });
  }
  @override
  public boolean oncreateoptionsmenu(menu menu) {
    // inflate the menu; this adds items to the action bar if it is present.
    getmenuinflater().inflate(r.menu.main, menu);
    return true;
  }
}

希望本文所述對大家android程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 奇米视频7777 | 传说之下羊妈挤羊奶网站 | 国产亚洲欧美在线中文bt天堂网 | tube69中国露脸 | 全是女性放屁角色的手游 | nxgx国产 | 2021日本三级理论影院 | 亚洲人成网站在线观看妞妞网 | 日韩一级片在线免费观看 | 国产不卡视频一区二区在线观看 | h高潮娇喘抽搐 | 精品国产视频 | 色吧五月婷婷 | 青草国产在线视频 | 91在线精品国产 | 91影视永久福利免费观看 | 好硬好大好浪夹得好紧h | 美女脱了内裤打开腿让人桶网站o | 99re这里只有精品视频在线观看 | 日本红色高清免费观看 | 国产日韩在线 | 欧美一区二区三区gg高清影视 | 国产色视频一区二区三区 | 91香蕉视频导航 | 四虎影院新网址 | 国产精品福利在线观看入口 | 日韩 国产 欧美 | 1024免费永久福利视频 | 国产高清在线精品一区二区 | 国产99青草全福视在线 | b站免费| 护士xxxx| 久久精品国产亚洲AV天美18 | 啊好大好爽 | 国产精品嫩草影院一二三区入口 | 国产农村乱子伦精品视频 | 欧美日韩国产亚洲一区二区 | 啪一啪日一日 | 风间由美被义子中文字幕 | 24adc年龄18岁欢迎大驾光临 | 精品一区二区三区免费观看 |