无法应用对话框

时间:2015-08-11 12:42:26

标签: java android if-statement dialog

我需要检查我的应用程序的以下信息,如果文本等于“Alpha”,那么它会启动一个新的活动,否则它将继续通常的代码。实际上,“sendPack”中的常用代码在没有“if”规则的情况下工作正常。

我遇到了这个问题,不知道如何从这里开始。 它可能是一个愚蠢的错误,对此感到抱歉。 如何解决?

public void Send(View view) throws IOException {

        BdLocal bd = new BdLocal(this);
        String text = bd.getEmpId();

    if (text.equals("Alpha")) {

        Intent intent = new Intent(BetaActivity.this, AlphaSetup.class);
        startActivityForResult(intent, 0);

    } else {
        new transmitirInspecao().execute();
    }

}
 public class sendPack extends AsyncTask<String, Void, String> { 
    ProgressDialog pdialog;
    int boxSelected = 0;

    @Override
    protected String doInBackground(String... params) {
        BdLocal bd = new BdLocal(getApplicationContext());
        BdCloud bdc = new BdCloud();
        String ret = null;
        for (CheckBox aCheckBoxArrayList : checkBoxArrayList) {
            if (aCheckBoxArrayList.isChecked()) {
                boxSelected++;
                try {
                    int id = (Integer) aCheckBoxArrayList.getTag();
                    Pack pack = bd.readPackID(id);
                    ret = bdc.sendPack(pack, params[0], bd.getDspHash());
                    ret = ret.trim();
                    if (ret.equals("sucess".trim())) {
                        bd.MarkAsSend(id);
                    }
                } catch (IOException e) {
                    //e.printStackTrace();
                }
            }
        }
        if (boxSelected <= 0) {
            return "none";
        }
        return ret;
    }


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pdialog = new ProgressDialog(BetaActivity.this);
        pdialog.setCanceledOnTouchOutside(false);
        pdialog.setMessage(getResources().getString(R.string.send));
        pdialog.show();
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        pdialog.dismiss();
        String msg = "Null";
        if (result.equals("success")) {
            msg = getResources().getString(R.string.success_send);
        } else if (result.equals("img")) {
            msg = getResources().getString(R.string.error_ftp);
        } else if (result.equals("oper")) {
            msg = getResources().getString(R.string.error_operation);
        } else if (result.equals("none")) {
            msg = getResources().getString(R.string.non_selected);
        } else {
            msg = getResources().getString(R.string.error_send);
        }
        AlertDialog alert;
        AlertDialog.Builder builder = new AlertDialog.Builder(BetaActivity.this);
        builder.setMessage(msg);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = getIntent();
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                finish();
                startActivity(intent);
            }
        });
        alert = builder.create();
        alert.show();


        final Dialog login = new Dialog(this); //here is the message "Dialog cannot be applied" to Send, what should i do?
        login.setContentView(R.layout.ins_dialog);
        login.setTitle(R.string.insira_dados_op);
        Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
        Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
        final EditText txtUsername = (EditText) login.findViewById(R.id.txtUsername);
        final EditText txtPassword = (EditText) login.findViewById(R.id.txtPassword);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (txtUsername.getText().toString().trim().length() > 0) {
                    if (txtPassword.getText().toString().trim().length() > 0) {
                        BdCloud bdc = new BdCloud();
                        BdLocal bdl = new BdLocal(BetaActivity.this);
                        String[] ret = bdc.loginOp(txtUsername.getText().toString().trim(), txtPassword.getText().toString().trim(), bdl.getDspHash());
                        if (ret[0].equals("true")) {
                            new Send().execute(ret[1]);
                            login.dismiss();
                        } else {
                            Toast.makeText(betaActivity.this, getResources().getString(R.string.error_inval), Toast.LENGTH_LONG).show();
                        }
                    } else {
                        txtPassword.setError(getResources().getString(R.string.error_field_required));
                        txtPassword.requestFocus();
                    }
                } else {
                    txtUsername.setError(getResources().getString(R.string.error_field_required));
                    txtUsername.requestFocus();
                }
            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                login.dismiss();
            }
        });
        login.show();
    }

}

0 个答案:

没有答案