在android中长按共享链接或图像

时间:2014-02-27 07:24:27

标签: android facebook

我希望在长时间点击该链接时在Facebook上分享链接。我有意点击Facebook或点击按钮的东西,但我想要它长按链接。可以任何人帮助我。

public class MainActivity extends Activity {
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn = (Button) findViewById(R.id.btn);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent sharingIntent = new Intent(
                    android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            String shareBody = "Here is the share content body";
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Subject Here");
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    shareBody);
            startActivity(Intent.createChooser(sharingIntent, "Share via"));

        }
    });
}

}

2 个答案:

答案 0 :(得分:1)

只需使用按钮onLongclickListner,如下所示

button.setOnLongClickListener(new OnLongClickListener() { 
        @Override
        public boolean onLongClick(View v) {
            // your code goes here
            return true;
        }
    });

答案 1 :(得分:0)

使用onlongclick dude:)

   btn = (Button) findViewById(R.id.btn);
        btn.setOnLongClickListener(new setOnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {

                Intent sharingIntent = new Intent(
                        android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                String shareBody = "Here is the share content body";
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        "Subject Here");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        shareBody);
                startActivity(Intent.createChooser(sharingIntent, "Share via"));
                return true;

            }
        });