激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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

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

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

2021-04-26 17:44sgx425021234 Android

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

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

先看效果圖:

Android編程開發(fā)之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程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 99视频有精品视频高清 | 精品国产一区二区三区久久久蜜月 | 看免费黄色大片 | 视频一区二区三区中文字幕 | 欧美一级不卡视频 | 黄网站免费观看视频 | 国产免费人做人爱午夜视频 | 精品亚洲二区 | 五月婷婷天堂 | 日韩精品一区二区三区中文 | 成人午夜免费网站 | 凹凸成人精品亚洲精品密奴 | 国产成人综合在线观看 | 欧美日韩a∨毛片一区 | 亚洲电影在线播放 | 羞羞网站 | 视频一区二区精品 | 欧美aaa| 亚洲爱爱网站 | av成人免费在线观看 | 99久久久精品 | 久久国产精品电影 | 黑人日比视频 | 精品国产一区二区三区久久久 | 国产精品视频1区 | 国产黄色网页 | 久草视频国产在线 | 91一区二区三区久久久久国产乱 | 一本色道久久99精品综合蜜臀 | 欧美成人午夜 | 久久精品国产99久久久古代 | 欧美亚洲另类在线 | 成人黄色小视频网站 | 色无极影院亚洲 | 免费在线观看国产 | 欧美精品成人一区二区在线观看 | 日韩av在线网址 | 牛牛热这里只有精品 | 国产一区二区三区视频在线 | 性欧美xxxx极品摘花 | 日韩av一二三区 |