๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - ์ด๋ฉ”์ผ ํ˜•์‹ ์ฒดํฌํ•˜๋Š” ๋ฐฉ๋ฒ•(@ ์—ฌ๋ถ€ ํ™•์ธ, ์ด๋ฉ”์ผ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ) ๋ณธ๋ฌธ

๐Ÿค–Android/Java

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - ์ด๋ฉ”์ผ ํ˜•์‹ ์ฒดํฌํ•˜๋Š” ๋ฐฉ๋ฒ•(@ ์—ฌ๋ถ€ ํ™•์ธ, ์ด๋ฉ”์ผ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ)

๋ฃจ๋ฆฌ์•ผใ…‘ 2023. 12. 27. 17:02
๋ฐ˜์‘ํ˜•

 

์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ๊ฐœ๋ฐœ ์‹œ ์ด๋ฉ”์ผ๋กœ ํšŒ์›๊ฐ€์ž…์„ ํ•  ๋•Œ
์ด๋ฉ”์ผ์ด ์ž˜๋ชป ๋˜์—ˆ์„ ๋•Œ ๊ฒ€ํ† ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

@ ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž!

์ด๋ฉ”์ผ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

onClick ํ•จ์ˆ˜ ๋‚ด์—์„œ if  ๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ ๊ฒ€ํ† ํ•˜๊ณ 
์ž˜๋ชป ๋งŒ๋“ค์—ˆ๋‹ค๋ฉด Snackbar๋กœ ์•ˆ๋‚ด๋ฌธ๊ตฌ๋ฅผ ์•Œ๋ ค์ค€๋‹ค.

public class MainActivity extends AppCompatActivity {

    EditText editEmail;
    Button btnRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        editEmail = findViewById(R.id.editEmail);
        btnRegister = findViewById(R.id.btnRegister);


        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String email = editEmail.getText().toString().trim();


                if (email.contains("@") == false) {
                    Snackbar.make(btnRegister,"์ด๋ฉ”์ผ์„ ๋ฐ”๋ฅด๊ฒŒ ์ž…๋ ฅํ•˜์„ธ์š”.",
                            Snackbar.LENGTH_SHORT).show();
                    return;

                }


            }
        });




    }
}
๋ฐ˜์‘ํ˜•