0

我在用户可以输入密码和用户名的对话框中遇到问题。一旦用户输入数据并单击确定,此对话框不会关闭。

这是对话框:

private void askUserCredentials(String pWarning) {
        // starting the user credentials
        Log.v(tag, "askUserCredentials started ");

        // create the new dialog
        final Dialog dialogCredentials = new Dialog(this);

        //Set the content view to our xml layout
        dialogCredentials.setContentView(R.layout.dialog_login);

        // if there is a warning
        if (pWarning != null) {
            // show it instead of the regular text
            TextView dialogDescription = (TextView) dialogCredentials
                    .findViewById(R.id.dialog_cred_description);

            dialogDescription.setText(pWarning);

            // also set it to red
            //dialogDescription.setTextColor(R.color.text_headline_main);
        }

        // Set the title of the dialog. this space is always drawn even if blank
        // so might as well use it
        dialogCredentials
                .setTitle(getString(R.string.LABEL_DIALOG_CREDENTIALS));

        // get password and username
        String lUsername = SharedPrefHandler.getPrefString(
                getApplicationContext(), SharedPrefHandler.USER_NAME);
        String lPassword = SharedPrefHandler.getPrefString(
                getApplicationContext(), SharedPrefHandler.USER_PASSWORD);

        // to get the values later set the reference to the fields
        final EditText txtPassword = (EditText) dialogCredentials
                .findViewById(R.id.edit_text_password);
        final EditText txtUsername = (EditText) dialogCredentials
                .findViewById(R.id.edit_text_username);

        // preset the values
        if (lUsername != null)
            txtUsername.setText(lUsername);
        if (lPassword != null)
            txtPassword.setText(lPassword);

        // Allow the dialog to be cancelable
        dialogCredentials.setCancelable(true);

        Button okButton = (Button) dialogCredentials
                .findViewById(R.id.dialog_cred_butt_OK);
        Button canceButton = (Button) dialogCredentials
                .findViewById(R.id.dialog_cred_butt_cancel);

        okButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Log.v(tag, "Got some data - username:"
                        + txtUsername.getText().toString() + "-Password: "
                        + txtPassword.getText().toString());

                //close the dialog
                dialogCredentials.dismiss();

                // store them to the users settings
                SharedPrefHandler.storeSharedPref(getApplicationContext(),
                        txtUsername.getText().toString(),
                        SharedPrefHandler.USER_NAME);
                SharedPrefHandler.storeSharedPref(getApplicationContext(),
                        txtPassword.getText().toString(),
                        SharedPrefHandler.USER_PASSWORD);

                guiStatusMessage.setText("#Bitte warten.");

                //Start the sync in case the user just entered the credentials
                startSynchronisation();

                Log.i(tag,"started synch!"); //gets called after the function was executed
            }
        });

        // close the dialog if canceled
        canceButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                dialogCredentials.dismiss();

            }
        });

        dialogCredentials.show();
    }

用户输入凭据后,点击确定按钮。一切正常,但命令“startSynchronisation()”可能需要一段时间,并且对话框不会被关闭。同步正在另一个服务中运行,因此完全不清楚为什么对话框正在等待它。

private void startSynchronisation() {


        try {
            if (myServerServiceBound && myServerService != null)

                myServerService.IgetUserData();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

非常感谢帮助。这一定是架构问题,因为我在另一段代码中也有类似的问题。那里的选项菜单不会关闭。

谢谢

4

1 回答 1

0

缺少的是将调用设置为异步远程进程的 ONEWAY。

我花了一段时间才找到那个....

于 2012-08-30T20:55:10.003 回答