0

我有 2 个按钮,一个指向 Twitter URL,一个指向 Play Store URL。Twitter 可以工作,但 Play 商店按钮却不行。代码如下。

  //TWITTER BUTTON
    Button bt1 = (Button) findViewById(R.id.bTwitter);
    bt1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
                sendToTwitter();
        }
    });
}
            protected void sendToTwitter() {
                    String url = "http://twitter.com/neilk27";
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url)); 
                    startActivity(i);

    //DONATE BUTTON    
    Button bd1 = (Button) findViewById(R.id.bDonate);
    bd1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                    sendToStore();
            }
        });
    }
                protected void sendToStore() {
                        String url1 = "https://play.google.com/store/apps/developer?id=NK+Apps";
                        Intent i1 = new Intent(Intent.ACTION_VIEW);
                        i1.setData(Uri.parse(url1)); 
                        startActivity(i1);
4

1 回答 1

1

我不确定,但你的花括号似乎引起了一些问题。尝试这个 :

Button bt1 = (Button) findViewById(R.id.bTwitter);
bt1.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        sendToTwitter();
    }
});
protected void sendToTwitter() {
    String url = "http://twitter.com/neilk27";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url)); 
    startActivity(i);
}
//DONATE BUTTON    
Button bd1 = (Button) findViewById(R.id.bDonate);
bd1.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        // TODO Auto-generated method stub
        sendToStore();
    }
});
protected void sendToStore() {
    String url1 = "https://play.google.com/store/apps/developer?id=NK+Apps";
    Intent i1 = new Intent(Intent.ACTION_VIEW);
    i1.setData(Uri.parse(url1)); 
    startActivity(i1);
}
于 2012-09-30T16:23:27.627 回答