0

在转到下一个编码语句之前,我想知道如何完全执行任何功能。

    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.btnBack:
        i = new Intent(SetUpActivity.this, HomeActivity.class);
        finish();
        break;
    case R.id.btnOne:
        showDisclaimerDialog();
        Log.d("agreed value", agreed+"");
        if (agreed) {
            Log.e("Inside", "btnOne");
            appObj.setMaxFeeds(1);
            i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
            startActivity(i);
        }
        break;
    case R.id.btnTwo:
        showDisclaimerDialog();
        if(agreed) {
            appObj.setMaxFeeds(2);
            i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
            startActivity(i);
        }
        break;
    case R.id.btnFive:
        showDisclaimerDialog();
        if (agreed) {
            appObj.setMaxFeeds(5);
            i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
            startActivity(i);
        }
        break;

    default:
        break;
    }


private void showDisclaimerDialog() {
    // TODO Auto-generated method stub
    AlertDialog.Builder builder = new AlertDialog.Builder(
            SetUpActivity.this);
    builder.setTitle("Disclaimer");
    builder.setMessage(Html.fromHtml(getString(R.string.disclaimer)));
    builder.setPositiveButton("I Agree",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    agreed = true;
                    Log.e("Inside I agree",agreed+"");
                }
            });
    builder.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    agreed = false;
                    Log.e("Inside Cancel",agreed+"");
                }
            });

    builder.create().show();
    agreed=false;
    Log.e("Inside dialog",agreed+"");

}

当我点击“btnOne”时,执行的控制应该转到“showDiclaimerDialog()”而不执行进一步的语句,这些语句是

        Log.d("agreed value", agreed+"");
    if (agreed) {
        Log.e("Inside", "btnOne");
        appObj.setMaxFeeds(1);
        i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
        startActivity(i);
    }
4

1 回答 1

1

你不能(因为你可以但真的真的不应该)阻止 GUI 线程中的执行。有关详细信息,请参阅此问题。

Dialogs / AlertDialogs:如何在对话框启动时“阻止执行”(.NET 样式)

于 2012-09-26T07:53:01.853 回答