在android中单击edittext后禁用clickevent

时间:2017-07-02 18:10:10

标签: java android android-edittext mouseclick-event

有一个edittext视图,用户应该输入有效的电子邮件地址。Click handler自动添加允许的域“@ stackoverflow.com”。我的意思是如果你点击edittext程序,java将文本设置为@ stackoverflow.com 用户输入他们的ID,如nameSurname@stackoverflow.com

问题是,如果你输入了错误的字符并再次点击edittext,它会再次设置文本@ stackoverflow.com

示例nameSrname@stackoverflow.com但您要输入nameSurname@stackoverflow.com,请单击edittext进行修复,但它再次为@ stackoverflow.com。

如何禁用第二,第三...点击事件但只启用第一次点击事件?

为什么我无法在没有点击事件的情况下设置文字?因为我不能显示提示文本。

1 个答案:

答案 0 :(得分:0)

点击

添加验证
//Define variables.
float amp = 0.0;
float freq = 0;
int totalwavelength = 50;
int mouse = 0;


void draw(){
    background(0);
    freq = 0;

    while (freq < totalwavelength) {
        //When button is not pressed, run this script:
        if (mouse == 0) {
            fill(255);
            ellipse(freq * 50 + 20, sin(amp) * 100 + 450, 20, 20); 
            freq += 1;
            amp += 0.5;

            //Create Button
            fill(255);
            rect(800, 800, 200, 100);

            //Mouse Coordinates
            fill(255, 0, 0);
            text("X=" + mouseX, mouseX, mouseY - 10);
            text("Y=" + mouseY, mouseX, mouseY);

            //Button script
            if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 && mousePressed == true && mouse == 0) {
                mouse = 1;
            } 

            if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 && mousePressed == true && mouse == 1) {
                mouse = 0;
            } 
        }


        //When button pressed run this script:
        if (mouse == 1) {
            fill(255);
            ellipse(freq * 50 + 20, sin(amp) * 100 + 450, 20, 20); 
            freq += mouseX;
            amp += mouseY;

            //Create Button
            fill(255);
            rect(800, 800, 200, 100);

            //Button script
            if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 && 
       mousePressed == true && mouse == 0) {
                mouse = 1;
            } 

            if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 && 
                mousePressed == true && mouse == 1){
                mouse = 0;
            } 

        }
    }
}