views:

101

answers:

2

I'm writing an application with EditText driven widget. and I'd like to create my own copy & paste menu. To replace android default menu on EditText, what should I do? Just overriding long click? or is there another way to implement? Thanks in advance.

+1  A: 

It is considered to be somewhat of a standard exercise to implement copy/paste the hard way by overwriting the menu system, creating the menu items yourself, and your own internal buffer.

However, that is not how it should be done if a better way is available on the platform. Reimplementing platform functions is good for learning but bad for maintenance.

Community Wiki as this is not a real answer and I should not get rep for this.

Joshua
skysign
@Joshua: A comment is generally better for this kind of thing
Casebash
@casebash well since it got accepted answer it obviously wasn't.
Joshua
@Joshua: You said its not a real answer yourself. If you don't believe its a real answer and you don't need either to format code or the extra characters, then you should use a comment. If, on the other hand, you think it is a real answer, then you shouldn't say it isn't.
Casebash
A: 

EditText should already have a context menu enabled. If it were not, then you would have to enable it by calling registerForContextMenu. Once you have the context menu enabled, you have to add items to it. This is done in onCreateContextMenu by using one of the Menu.add methods.

The hard part is writing the code for onContextItemSelected after the user has selected an option. Saving text to the clipboard is simply a matter of calling ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText("myText");. However, first we need to find what text to copy. I haven't figured this last part out yet, but I am hopeful that I will soon.

Related Questions

Casebash