【问题标题】:how to open an activity with fragments from an other activity android如何使用来自其他活动android的片段打开一个活动
【发布时间】:2021-05-15 17:24:06
【问题描述】:

这是主要活动的代码

 package com.example.login;

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

  import androidx.appcompat.app.AppCompatActivity;

  public class MainActivity extends AppCompatActivity {
  DatabaseHelper helper=new DatabaseHelper(this);
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   }

    public  void onBtnLoginInClick(View v){
    if(v.getId()==R.id.btnLoging){
        //Passing userName
        EditText UserNameET=(EditText) findViewById(R.id.Edname);
        String UserNameStr=UserNameET.getText().toString();
        //Passing Password
        EditText PasswordET=(EditText)findViewById(R.id.Edpassword);
        String PasswordStr=PasswordET.getText().toString();


        String dbPassword=helper.LoginIn(UserNameStr);
        //Send UserName to Database to find it, and return Password
        //To compare it with Current Password from user input
        if(dbPassword.equals(PasswordStr)){
            Intent loginIntent=new Intent(this, accueil.class);
            loginIntent.putExtra("UserName",UserNameStr);
            loginIntent.putExtra("Password",PasswordStr);
            startActivity(loginIntent);
        }else {
            Toast.makeText(this, "UserName and Passwords dont match", Toast.LENGTH_SHORT).show();
        }


       }
       }

      public void onBtnSignUoClick(View v){
       if(v.getId()==R.id.btnSignUp){
        Intent SignUpIntent=new Intent(this,signup.class);
        startActivity(SignUpIntent);
        }
        }

        }

这是我要打开的活动,在此活动中有一个片段菜单

 package com.example.myapplication;

 import androidx.appcompat.app.AppCompatActivity;

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

 public class accueil extends AppCompatActivity {

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

编译我的 I 代码时,我没有收到任何错误,但我无法从登录我的主要活动重新定位到 acceuil(具有底部菜单的活动)

【问题讨论】:

  • 你有什么异常或错误吗?

标签: android android-studio android-fragments android-intent


【解决方案1】:

我认为您无法获取 dbPassword 值的问题。首先尝试将这一行放在 onCreate 方法中

DatabaseHelper helper=new DatabaseHelper(this);

那么请检查您是否获得了 String dbPassword 值。那我想问题就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    相关资源
    最近更新 更多