如果用户名和密码正确,请切换到2.活动性

发布于 2025-02-13 00:54:40 字数 1024 浏览 1 评论 0原文

我是Android的新手,我为自己编写了一个代码,按下按钮时,它将切换到另一个活动,但我想将其连接到密码和用户名。

如果“用户名& amp;密码”是正确的,则切换到活动2。 我该怎么做?


import androidx.appcompat.app.AppCompatActivity;

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

public class Giris_activity extends AppCompatActivity {

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_giris);

        button = (Button) findViewById(R.id.giris);
        button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                openbaslangic();
            }
        });

    }

    public void openbaslangic()
    {

        Intent intent = new Intent(this, Baslangic_activity.class);
        startActivity(intent);
        finish();

    }
}```

I'm new to android, I wrote a code for myself, when the button is pressed, it switches to another activity, but I want to connect it to the password and user name.

if "username && password" is correct then switch to activity 2.
how can I do it?


import androidx.appcompat.app.AppCompatActivity;

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

public class Giris_activity extends AppCompatActivity {

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_giris);

        button = (Button) findViewById(R.id.giris);
        button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                openbaslangic();
            }
        });

    }

    public void openbaslangic()
    {

        Intent intent = new Intent(this, Baslangic_activity.class);
        startActivity(intent);
        finish();

    }
}```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2025-02-20 00:54:40

在此之后,您还必须找到文本字段(用户名和密码),

EditText username = (EditText) findViewById(R.id.username); 
EditText password= (EditText) findViewById(R.id.password);

必须在openbaslangic()中检查两个字段,例如:

if (username.getText().toString() == "your desired username" && password.getText().toString() == "your desired password") {
    Intent intent = new Intent(this, Baslangic_activity.class);
    startActivity(intent);
    finish();
}

You must also find text fields (username and password)

EditText username = (EditText) findViewById(R.id.username); 
EditText password= (EditText) findViewById(R.id.password);

After that you must check validation both field with Your desired values in openbaslangic() like this:

if (username.getText().toString() == "your desired username" && password.getText().toString() == "your desired password") {
    Intent intent = new Intent(this, Baslangic_activity.class);
    startActivity(intent);
    finish();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文