Cule :
My code reads like this:
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.share:
// send copy text
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = returnedText.getText().toString();
String shareSub = "";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share using"));
Toast.makeText(getApplicationContext(),getString(R.string.send_text), Toast.LENGTH_SHORT).show();
break;
}
switch (item.getItemId()) {
case R.id.copy:
// copy text to clipboard
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(returnedText.getText());
Toast.makeText(getApplicationContext(),getString(R.string.copy_text), Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
What do I need? Forbid click on a Share if they did not click on the Copy first. If they did not click first to Copy, the app to inform the Toast message that they must Copy the text, and then, when they clicked on the Copy, the menu item to Share has its own function.
madhu s :
try this not sure if it works.
- make ClipboardManager global.
in case R.id.share:
if (clipboardManager.hasPrimaryClip()){ // do what ever. }else { Toast.makeText(getApplicationContext(),"please click on copy first and try again",Toast.LENGTH_LONG).show(); }