开发者

Error Calling Intent

开发者 https://www.devze.com 2023-03-05 10:11 出处:网络
There is an error when I call t开发者_JAVA技巧he intent startActivity (new Intent (this, Advogado1.class)), How should I proceed to properly call this Intent

There is an error when I call t开发者_JAVA技巧he intent startActivity (new Intent (this, Advogado1.class)), How should I proceed to properly call this Intent

            AlertDialog.Builder alert = new AlertDialog.Builder(this);

            alert.setTitle("Atenção");
            alert.setMessage("Digite o Numero da OAB");

            // Set an EditText view to get user input
            final EditText input = new EditText(this);
            alert.setView(input);

            alert.setPositiveButton("Ok",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int whichButton) {

                            int oab = Integer.parseInt(input.getText()
                                    .toString());
                            // Do something with value!

                            if (oab == 1) {

                                startActivity(new Intent(this, Advogado1.class));
                            }

                        }
                    });

            alert.setNegativeButton("Cancelar",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int whichButton) {
                            // Canceled.
                        }
                    });

            alert.show();


The call to,

startActivity(new Intent(this, Advogado1.class));

should not use 'this', it should use,

startActivity(new Intent(NameOfYourActivity.this, Advogado1.class)); 

because this refers to the anonymous class extending DialogInterface.OnClickListener, and not your Activity class. The Intent needs the caller class to be an instance of Activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号