开发者

Android rate button syntax errors

I get the errors Syntax error on token "marketrate", VariableDeclaratorId expected after this token... Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway");

and

Synt开发者_C百科ax error on token(s), misplaced construct(s)...startActivity(market);

        private void makeDialog() {     

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

        about.setMessage("About The Giveaway");

        about.setPositiveButton("Rate", new DialogInterface.OnClickListener() {
            Intent market = new Intent(
                    "android.intent.action.VIEW", 

                startActivity(market);
            public void onClick(DialogInterface arg0, int arg1) {
//action
            }
        });

        about.setNegativeButton("Close", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {}
        });

        about.show();
    }

}


I think you've got two problems.

First, you've got mismatched brackets here:

Intent market = new Intent(
    "android.intent.action.VIEW", 
    Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway");
startActivity(market);

I think you need an extract bracket after the Uri.parse call, to close the Intent constructor call:

Intent market = new Intent(
    "android.intent.action.VIEW", 
    Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway"));
startActivity(market);

Or extract the Uri.parse call out to start with:

Uri uri = Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway");
Intent market = new Intent("android.intent.action.VIEW", uri);
startActivity(market);

Second, you've got effectively a block of code in your OnClickListener() inner subclass, not in an initializer block or a method. Did you mean to put it in the onClick handler?

about.setPositiveButton("Rate", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
        Uri uri = Uri.parse("...");
        Intent market = new Intent("android.intent.action.VIEW", uri);
        startActivity(market);
    }
});


Please try this, I had tested the code and working as per requirement..

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

    about.setMessage("About The Giveaway");

    about.setPositiveButton("Rate", new DialogInterface.OnClickListener() 
    {
        Intent market = new Intent("android.intent.action.VIEW",Uri.parse("https://market.android.com/details?id=com.synamegames.giveaway"));

        public void onClick(DialogInterface arg0, int arg1) 
        {
                    //action
            startActivity(market);  

        }
    });

    about.setNegativeButton("Close", new DialogInterface.OnClickListener() 
    {
        public void onClick(DialogInterface arg0, int arg1) 
        {

        }
    });

    about.show();

try to run the code in Main/UI Thread.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜