Android_7일차

  • 실습하기
  • 메인 화면
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class kakaoLoginActivity extends AppCompatActivity {
    Button btn_login;
    EditText edtEmail, edtPass;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kakao_login);
        edtEmail = findViewById(R.id.edtEmail);
        edtPass = findViewById(R.id.edtPass);

        btn_login = findViewById(R.id.btn_login);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String email = edtEmail.getText().toString();
                String pass = edtPass.getText().toString();
                Intent intent = new Intent(kakaoLoginActivity.this,LoginResultActivity.class);
                intent.putExtra("email",email);
                intent.putExtra("pass",pass);

                startActivity(intent);
            }
        });
    }
}
  • 출력 화면
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class LoginResultActivity extends AppCompatActivity {
    TextView text12;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_result);
        Intent intent = getIntent();
        
        String email =  intent.getStringExtra("email");
        String pass =  intent.getStringExtra("pass");
        text12 = findViewById(R.id.tvLoginResult);

        if (email.equals("123") && pass.equals("123")){
            text12.setText("로그인 성공");
        }else{
            text12.setText("로그인 실패");
        }
    }
}
  • 결과

좋은 웹페이지 즐겨찾기