【问题标题】:Why is this Google + basic sharing not working?为什么此 Google+ 基本共享不起作用?
【发布时间】:2016-04-01 16:25:48
【问题描述】:
import android.content.Intent;
import android.net.Uri;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button shareButton = (Button) findViewById(R.id.share_button);
    shareButton.setOnClickListener( 

        new OnClickListener() {

            public void onClick (View v) {
                // Launch the Google+ share dialog with attribution to your app.
                Intent shareIntent = new PlusShare.Builder(this)
                    .setType("text/plain")
                    .setText("Welcome to the Google+ platform.")
                    .setContentUrl(Uri.parse("https://developers.google.com/+/"))
                    .getIntent();

                startActivityForResult(shareIntent, 0);
            }
        }
    );
}

我在“OnClickListener”和“(View V)”上遇到错误,我也接近 Java 和 Android 的初学者,试图添加一些基本的 Google 和共享,所以请帮助我

【问题讨论】:

标签: java android onclicklistener sharing


【解决方案1】:

你不能在类块中调用方法,你必须在方法中进行。

public class MainActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState){
        Button shareButton = (Button) findViewById(R.id.share_button);
        shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v){
                //your code
            }
        });
    }
}

【讨论】:

  • 现在 PlusShare 是红色的
  • PlusShare 不是 Android SDK 的一部分。我预计它会来自您引用的库。那个coden-p是从哪里来的?
  • 来自 Google+ 开发者页面
  • 然后将他们的库添加为 gradle 依赖项。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-17
  • 2019-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-26
  • 2011-10-29
相关资源
最近更新 更多