0
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;
}
}
あなたが送りたいものを表すプレーンテキストで、 'STRING'に渡す必要があります。あなたがここで共有したいテキストを知っている唯一の人なので、この文字列の出所を自分で決めなければなりません。 – CommonsWare
ああ、ユーザーが入力したテキストを送信することは本当に不可能ですか? – Kimochis
いいえ、それは非常に可能です。ただし、ユーザーがこのテキストをどこに入力しているのかはわかりません。あなたのソースコードは、例えば 'EditText'の兆候を示さない。 – CommonsWare