karan
karan

Reputation: 8853

implementing alert dialog in android api 11 or +

I am trying to do the following code below,but it returns error. may target is api-12 and minsdkversion is set to 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", "[email protected]");

                            // 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;
    }
}

how to resolve this. thnx in advance.

Upvotes: 1

Views: 685

Answers (1)

eternay
eternay

Reputation: 3814

AlertDialogManager is not an Android class. To make a dialog box, you should use AlertDialog.Builder instead. Just have a look at the documentation here.

Upvotes: 1

Related Questions