Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a progress bar to the login activity while logging in?

im creating an app to log in to parse.com and then browse thru projects and other functions but im not able to add a progress bar or anything similar so while the app is loging in nothing is happening im just waiting it to log in and move to the other activity

this is my code for the logging in any help please

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

    import com.androidbegin.parselogintutorial.R;
    import com.parse.LogInCallback;
    import com.parse.ParseException;
    import com.parse.ParseUser;


    public class LoginActivity extends Activity {
        // Declare Variables
        Button loginbutton;
        String usernametxt;
        String passwordtxt;
        EditText password;
        EditText username;

        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from login.xml
            setContentView(R.layout.login);
            // Locate EditTexts in login.xml
            username = (EditText) findViewById(R.id.username);
            password = (EditText) findViewById(R.id.password);

            // Locate Buttons in main.xml
            loginbutton = (Button) findViewById(R.id.login);


            // Login Button Click Listener
            loginbutton.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {
                    // Retrieve the text entered from the EditText
                    usernametxt = username.getText().toString();
                    passwordtxt = password.getText().toString();

                    // Send data to Parse.com for verification
                    ParseUser.logInInBackground(usernametxt, passwordtxt,
                            new LogInCallback() {
                                public void done(ParseUser user, ParseException e) {
                                        // If user exist and authenticated, send user to Welcome.class
                                    if(user !=null){    
                                    Intent intent = new Intent(
                                                LoginActivity.this,
                                                AddUserPage.class);
                                        startActivity(intent);
                                        Toast.makeText(getApplicationContext(),
                                                "Successfully Logged in",
                                                Toast.LENGTH_LONG).show();
                                        finish();
                                }else{
                                    Toast.makeText(getApplicationContext(), "No such user", Toast.LENGTH_LONG).show();
                                    username.setText("");
                                    password.setText("");
                                }}
                            });
                }
            });



        }
    }

like image 233
Georges Badra Avatar asked Dec 26 '22 01:12

Georges Badra


1 Answers

Define a progress bar as private ProgressDialog mProgress;

in oncreate use this

mProgress = new ProgressDialog(context);
mProgress.setTitle("Processing...");
mProgress.setMessage("Please wait...");
mProgress.setCancelable(false);
mProgress.setIndeterminate(true);

Now this

// Login Button Click Listener
    loginbutton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            mProgress.show();
            // Retrieve the text entered from the EditText
            usernametxt = username.getText().toString();
            passwordtxt = password.getText().toString();

            // Send data to Parse.com for verification
            ParseUser.logInInBackground(usernametxt, passwordtxt,
                    new LogInCallback() {
                        public void done(ParseUser user, ParseException e) {
                                // If user exist and authenticated, send user to Welcome.class
                            if(user !=null){   
                            mProgress.dismiss(); 
                            Intent intent = new Intent(
                                        LoginActivity.this,
                                        AddUserPage.class);
                                startActivity(intent);
                                Toast.makeText(getApplicationContext(),
                                        "Successfully Logged in",
                                        Toast.LENGTH_LONG).show();
                                finish();
                        }else{
                            mProgress.dismiss();
                            Toast.makeText(getApplicationContext(), "No such user", Toast.LENGTH_LONG).show();
                            username.setText("");
                            password.setText("");
                        }}
                    });
        }
    });
like image 52
Rohit5k2 Avatar answered Feb 02 '23 04:02

Rohit5k2