gpt4 book ai didi

java - 在 Android Activity 中切换 Activity

转载 作者:太空宇宙 更新时间:2023-11-04 13:19:43 25 4
gpt4 key购买 nike

每当我尝试单击按钮并切换 Activity 时,它总是会给我错误并保持相同的 Activity 而不执行任何操作:

W/EGL_emulation: eglSurfaceAttrib not implemented

W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6d42940, error=EGL_SUCCESS

我以为这是我的 list 文件中的内容,但我找不到任何内容。我尝试过改变很多东西并插入不同的过滤器等等,但没有任何方法可以解决这个问题。

我的代码是:

  1. AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.robertmonks.mytestapp" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name="Main_Activity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Login_Activity"
android:label="@string/title_activity_login_"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name="Register_Activity"
android:label="@string/title_activity_register_"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
</manifest>
  • Main_Activity
  • package com.example.robertmonks.mytestapp;

    import android.app.AlertDialog;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.app.AlertDialog;

    public class Main_Activity extends AppCompatActivity {

    android.widget.Button logoutButton;
    android.widget.EditText password;
    android.widget.EditText username;

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

    password = (android.widget.EditText) findViewById( R.id.etPassword );
    username = (android.widget.EditText) findViewById( R.id.etEmailAddress );
    logoutButton = (android.widget.Button) findViewById( R.id.blogin);

    logoutButton.setOnClickListener(new android.widget.Button.OnClickListener() {
    @Override
    public void onClick(View v) {
    if (v.getId() == R.id.blogin) {
    logoutButtonClicked();//move action to new method to keep code clean
    }
    }
    });

    }


    private void logoutButtonClicked()
    {
    android.content.Intent loginintent = new android.content.Intent(Main_Activity.this, Login_Activity.class);
    Main_Activity.this.startActivity(loginintent);
    android.util.Log.d("Logout", "Attempted");
    }

    }
  • 登录 Activity
  • package com.example.robertmonks.mytestapp;

    import android.app.AlertDialog;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.app.AlertDialog;

    public class Login_Activity extends AppCompatActivity {

    android.widget.Button loginButton;
    android.widget.Button registerButton;
    android.widget.EditText password;
    android.widget.EditText username;

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

    password = (android.widget.EditText) findViewById( R.id.etPassword );
    username = (android.widget.EditText) findViewById( R.id.etEmailAddress );
    loginButton = (android.widget.Button) findViewById( R.id.blogin);
    registerButton = (android.widget.Button) findViewById( R.id.bregister);

    loginButton.setOnClickListener(new android.widget.Button.OnClickListener(){
    @Override
    public void onClick(View v) {
    if(v.getId() == R.id.blogin) {
    loginButtonClicked();//move action to new method to keep code clean
    }
    if(v.getId() == R.id.bregister) {
    registerButtonClicked();
    }
    }
    });

    registerButton.setOnClickListener(new android.widget.Button.OnClickListener(){
    @Override
    public void onClick(View v) {
    if(v.getId() == R.id.bregister) {
    registerButtonClicked();
    }
    }
    });

    }

    private void loginButtonClicked()
    {

    //startActivity(Main_Activity.class);
    android.util.Log.d("Login", "Attempted");
    }

    private void registerButtonClicked()
    {
    android.content.Intent registerintent = new android.content.Intent(Login_Activity.this, Register_Activity.class);
    Login_Activity.this.startActivity(registerintent);
    android.util.Log.d("New User", "Attempted");
    }

    }
  • Registration_Activity
  • package com.example.robertmonks.mytestapp;

    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;

    public class Register_Activity extends AppCompatActivity {


    android.widget.Button createAccountButton;
    android.widget.Button LoginPageButton;
    android.widget.EditText password1;
    android.widget.EditText password2;
    android.widget.EditText FirstName;
    android.widget.EditText LastName;
    android.widget.EditText EmailAddress;

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

    password1 = (android.widget.EditText) findViewById( R.id.etFirstPassword );
    password2 = (android.widget.EditText) findViewById( R.id.etSecondPassword );
    FirstName = (android.widget.EditText) findViewById( R.id.etFirstName );
    LastName = (android.widget.EditText) findViewById( R.id.etLastName );
    createAccountButton = (android.widget.Button) findViewById( R.id.blogin);
    LoginPageButton = (android.widget.Button) findViewById( R.id.bregister);
    EmailAddress = (android.widget.EditText) findViewById( R.id.etEmailAddress);

    createAccountButton.setOnClickListener(new android.widget.Button.OnClickListener(){
    @Override
    public void onClick(View v) {
    if(v.getId() == R.id.blogin) {
    createAccountButtonClicked();//move action to new method to keep code clean
    }
    }
    });

    LoginPageButton.setOnClickListener(new android.widget.Button.OnClickListener() {
    @Override
    public void onClick(View v) {
    if (v.getId() == R.id.bregister) {
    LoginPageButtonClicked();
    }
    }
    });

    }

    private void createAccountButtonClicked()
    {
    android.util.Log.d("Create Account", "Attempted");
    }

    private void LoginPageButtonClicked()
    {
    android.util.Log.d("Login Page", "Attempted");
    android.content.Intent loginintent = new android.content.Intent(this, Login_Activity.class);
    startActivity(loginintent);
    }

    }

    最佳答案

    对于所有按钮,尝试更改 onclicklistener。
    例如对于注册按钮,

     registerButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    // Perform action on click
    }
    });

    我希望这有帮助。干杯:)

    关于java - 在 Android Activity 中切换 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33194299/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com