进度对话框登录活动

时间:2015-02-03 10:26:41

标签: android progressdialog

有人可以帮助我如何以及在哪里将progressdialog放在我的登录活动上,我是开发Android应用程序的新手,我想了解更多,请帮助我..这就是我想要的,如果用户单击登录按钮我想在检查数据库中的数据时显示进度对话框。 这是我的LoginActivity.java

public class LoginActivity extends Activity {
Button btnLogin;
Button btnLinkToRegister;
EditText inputRFnumber;
EditText inputPassword;
TextView loginErrorMsg;

// JSON Response node names
private static String KEY_SUCCESS = "success";
private static String KEY_ERROR = "error";
private static String KEY_ERROR_MSG = "error_msg";
private static String KEY_UID = "uid";
public static String KEY_NAME = "name";
private static String KEY_RFNUMBER = "RFnumber";
private static String KEY_CREATED_AT = "created_at";
public static String KEY_NAMEPASS;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_login);

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);


    // Importing all assets like buttons, text fields
    inputRFnumber = (EditText) findViewById(R.id.loginRFnumber);
    //inputPassword = (EditText) findViewById(R.id.loginPassword);
    btnLogin = (Button) findViewById(R.id.btnLogin);
   // btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
    loginErrorMsg = (TextView) findViewById(R.id.login_error);



    // Login button Click Event
    btnLogin.setOnClickListener(new View.OnClickListener() {



        public void onClick(View view) {
            String RFnumber = inputRFnumber.getText().toString();
            //String password = inputPassword.getText().toString();
            UserFunctions userFunction = new UserFunctions();
            try {
                Log.d("Button", "Login");
                JSONObject json = userFunction.loginUser(RFnumber);



                // check for login response
                try {
                    if (json.getString(KEY_SUCCESS) != null) {
                        loginErrorMsg.setText("");
                        String res = json.getString(KEY_SUCCESS);
                        if (Integer.parseInt(res) == 1) {
                            // user successfully logged in
                            // Store user details in SQLite Database
                            DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                            JSONObject json_user = json.getJSONObject("user");
                            KEY_NAMEPASS = json_user.getString(KEY_NAME);


                            // Clear all previous data in database
                            userFunction.logoutUser(getApplicationContext());
                            db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_RFNUMBER), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));




                            // Launch Dashboard Screen
                            Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);


                            // Close all views before launching Dashboard
                            dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(dashboard);

                            // Close Login Screen
                            finish();
                        } else {
                            // Error in login
                            loginErrorMsg.setText("Incorrect Registration Number!");
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();

                Toast.makeText(getBaseContext(), "No network connection! Please try again later...", Toast.LENGTH_SHORT).show();

            }
        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

使用AsyncTask类。在AsyncTask中,您也可以更新进度状态。但是doInBackground方法中没有任何UI更改。我希望这对您有所帮助:)