当前位置: 首页 > 知识库问答 >
问题:

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

景靖琪
2023-03-14

我是android新手,我为自己写了一个代码,当按下按钮时,它会切换到另一个活动,但我想把它连接到密码和用户名。

如果“用户名”


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();

    }
}```

共有1个答案

欧阳安晏
2023-03-14

您还必须找到文本字段(用户名和密码)

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();
}
 类似资料:
  • 我有两个活动A和B。A启动活动B。在活动B中,我在按钮单击处理程序中调用setResult(RESULT_OK,intent),而不调用finish()-这是理想的行为。 旋转B并按back后,A的onActivityResult接收resultCode的RESULT_Cancelled,而不是RESULT_ OK。 我知道这是因为活动B在旋转时被破坏了。确保从B返回正确的结果代码的常见做法是什么

  • 早上好,我在登录使用Spring Security的应用程序时遇到了问题。每次我尝试登录时(即使用户名和密码正确),应用程序都会将我重定向到失败url(在我的情况下是:/login?error=true)。密码是用BCrypt加密的,我使用MySQL数据库来存储它们。 应用程序基于Spring in Action 5:https://github.com/habuma/spring-in-acti

  • 我有一个PHP网页,其中我配置了aws sdk并实例化了cognito客户机。客户机也配置了一个客户机密码,并且启用了auth flows USER\u PASSWORD\u auth、USER\u SRP\u auth。具有基本身份验证流类型USER\u PASSWORD\u auth的initiateAuth对我来说很好。下面是我尝试过的示例用法- 通过这种方式,我们获得了一个带有access

  • 我是Ctakes的新用户。我遵循了用户安装指南并添加了UMLS访问权限。在我编辑了runctakescpe.bat和runctakescvd.bat之后,我得到了以下内容: F:\apache-CTAKES-4.0.0>设置CTAKES_HOME=F:\apache-CTAKES-4.0.0 f:\apache-ctakes-4.0.0>如果存在“f:\apache-ctakes-4.0.0\bi

  • 问题内容: 这里发布了一个类似的问题:REST API服务针对验证失败返回什么合适的HTTP状态代码? 上面线程中的答案指出:“例如,如果URI应该具有ISO-8601日期,而您发现它的格式错误或引用的日期是2月31日,则您将返回HTTP 400。实体主体中格式正确的XML,并且无法解析。” 但是,如果用户提交了正确格式的数据会怎样?我的意思是,用户为用户名和密码提交了纯字母字符串/文本(这对我的

  • 这里发布了一个类似的问题:对于验证失败,REST API服务返回的适当HTTP状态代码是什么? 但是,如果用户提交了正确格式的数据,会发生什么呢?我的意思是,用户为用户名和密码提交了一个按字母顺序排列的字符串/文本(这对我的应用程序完全有效)。唯一的问题是密码与用户名不匹配。在这种情况下,400将是不正确的,因为它是完全有效的语法和格式良好的。 401将是不正确的(正如这里所建议的:哪个HTTP状