逐个执行功能

时间:2012-09-26 07:48:50

标签: java function

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

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

1 个答案:

答案 0 :(得分:1)

你不能(如你所能,但实际上真的不应该)阻止GUI线程中的执行。有关详细信息,请参阅此问题。

Dialogs / AlertDialogs: How to "block execution" while dialog is up (.NET-style)