1

我正在尝试执行以下代码,但它返回错误。可能目标是 api-12 并且 minsdkversion 设置为 api-11

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {

    // Email, password edittext
        EditText txtUsername, txtPassword;

        // login button
        Button btnLogin;

        // Alert Dialog Manager
        AlertDialogManager alert = new AlertDialogManager();   //here it says alertdialogmanager cannot be resolved to a type

        // Session Manager Class
        SessionManager session;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login); 

            // Session Manager
            session = new SessionManager(getApplicationContext());                

            // Email, Password input text
            txtUsername = (EditText) findViewById(R.id.txtUsername);
            txtPassword = (EditText) findViewById(R.id.txtPassword); 

            Toast.makeText(getApplicationContext(), "User Login Status: " + session.isLoggedIn(), Toast.LENGTH_LONG).show();


            // Login button
            btnLogin = (Button) findViewById(R.id.btnLogin);


            // Login button click event
            btnLogin.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // Get username, password from EditText
                    String username = txtUsername.getText().toString();
                    String password = txtPassword.getText().toString();

                    // Check if username, password is filled                
                    if(username.trim().length() > 0 && password.trim().length() > 0){
                        // For testing puspose username, password is checked with sample data
                        // username = test
                        // password = test
                        if(username.equals("test") && password.equals("test")){

                            // Creating user login session
                            // For testing i am stroing name, email as follow
                            // Use user real data
                            session.createLoginSession("Android Hive", "anroidhive@gmail.com");

                            // Staring MainActivity
                            Intent i = new Intent(getApplicationContext(), MainActivity.class);
                            startActivity(i);
                            finish();

                        }else{
                            // username / password doesn't match
                            alert.showAlertDialog(LoginActivity.this, "Login failed..", "Username/Password is incorrect", false);  //also here
                        }               
                    }else{
                        // user didn't entered username or password
                        // Show alert asking him to enter the details
                        alert.showAlertDialog(LoginActivity.this, "Login failed..", "Please enter username and password", false);  //and here
                    }

                }
            });
        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_login, menu);
        return true;
    }
}

如何解决这个问题。提前谢谢。

4

1 回答 1

1

AlertDialogManager不是 Android 类。要制作一个对话框,您应该使用AlertDialog.Builder。看看这里的文档。

于 2013-04-26T10:51:51.960 回答