我希望用户能够在单击FAB时共享消息。但是我应该在sendIntent.putExtra(Intent.EXTRA_TEXT, /* what should I put here*/);
放置什么?我尝试了消息,但它不起作用。
public class NoteDetailFragment extends Fragment {
public NoteDetailFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View fragmentLayout = inflater.inflate(R.layout.fragment_note_detail, container, false);
FloatingActionButton fab = (FloatingActionButton)fragmentLayout.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, /* what should I put here*/);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
});
TextView title = (TextView)fragmentLayout.findViewById(R.id.viewNoteTitle);
TextView message = (TextView)fragmentLayout.findViewById(R.id.viewNoteMessage);
TextView thoughts = (TextView)fragmentLayout.findViewById(R.id.viewNoteThoughts);
ImageView icon = (ImageView)fragmentLayout.findViewById(R.id.viewNoteIcon);
Intent intent = getActivity().getIntent();
title.setText(intent.getExtras().getString(MainActivity.NOTE_TITLE_EXTRA));
message.setText(intent.getExtras().getString(MainActivity.NOTE_MESSAGE_EXTRA));
thoughts.setText(intent.getExtras().getString(MainActivity.NOTE_THOUGHTS_EXTRA));
Note.Category noteCat = (Note.Category)intent.getSerializableExtra(MainActivity.NOTE_CATEGORY_EXTRA);
icon.setImageResource(Note.categoryToDrawable(noteCat));
return fragmentLayout;
}
}