1

为了在 facebook 上分享帖子(也是 gmail ,sms ...),我使用了

public class ShareActivity extends Activity {

    // the button + the editText
    Button button= (Button) findViewById(R.id.share);
    EditText text= (EditText)findViewById(R.id.edittext);   

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share);          

        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_SEND);
                // type of intent 
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT, text.getText().toString());
                ShareActivity.this.startActivity(Intent.createChooser(intent, "Share :  "));
            }
        });
    }      
}

但是当我开始我的活动时,它意外停止了

4

2 回答 2

0

最终代码:

公共类 ShareActivity 扩展 Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_share);     

 // the button + the editText
    Button button= (Button) findViewById(R.id.share);
    final EditText text= (EditText)findViewById(R.id.edittext);


    button.setOnClickListener(
            new OnClickListener() {
                public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_SEND);
                    // type of intent 
                        intent.setType("text/plain");
                        intent.putExtra(Intent.EXTRA_TEXT, text.getText().toString());
                        ShareActivity.this.startActivity(Intent.createChooser(intent, "Share :  "));
                }
                }
        );

}

}

于 2012-07-10T09:31:17.183 回答
0

通话text= (EditText)findViewById(R.id.edittext);后放置此线路。setContentView(R.layout.activity_share);

于 2012-07-09T10:14:36.797 回答