How can I write my own context menu for copy & paste? - android

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.

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
Show context menu when link is long pressed in TextView

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.

Related

Best control to be used as dropdown list in android

I have an activity which one of its components is a EditText. The goal of it is the following: when user clicks/taps on it, another activity is called to select some items (categories). I have implemented it using an activity that extends listactivity and using a custom adapter to paint custom rows for items.
All is ok, but I guess if using a EditText is the best option. The problem using this kind of control is that when user clicks/taps on it, the virtual keyboard appears and I do not want it to appear. If I use a TextView instead, virtual keyboard does not appear, but it is not clear for user that he have to click/tap on it to select a category (as the underscore line is not shown here as when using EditText).
So what android widget is the best to use in this scenario?
You can always use expandable list view there are many examples online that could help u to create it much more flexible than a spinner and it looks elegant and easy to use, it also show the user directly what is used for by just giving it a look and u can always customize it and play with its look and functionality.
Sounds like you are looking for a Spinner? That way you wouldn't have to load up a separate Activity to make the category selection. Otherwise, why not just use a Button? It's obviously clickable, that's for sure!

Editing the EditText context menu in Android

Is there a way to add a custom case to the existing context menu in Android? We all have a context menu that is called on the active EditText view, the one with "Input Type" and other. What I need is to add another case to this menu, say "Options". I honestly searched for info on Android Developers, but no luck over there. They only write about creating your own menu from scratch. I don't need to change it systemwide as this guy does. My only concern is to change it in one activity of my app, one instance of EditTextto be precise.
See https://stackoverflow.com/a/7383161/1351347
It is NOT possible to override the system-wide contextMenu. You could (as you already know) push another contextMenu on a longClick on this single EditText.

Is it possible to add some item in the context menus of android (system menu)

When I enter some text and press and hold on it then context menu is presented with items like cut,copy,select text and so on.
Is there any way to add my own custom item to this context menu ? I do not how this things works but I guess that should be possible to register something in the manifest just like registering activities and broadcasts . . .
Thanks,
Any ideas are wellcomed
Is there any way to add my own custom item to this context menu ?
Only for widgets in your own activities, not for the system as a whole.
Also, EditText is problematic even for your own activities, as some device manufacturers are bypassing the normal context menu system, so you can't add to them.
That being said, for your own activities, just follow the instructions to create a context menu for the widgets of interest.
Have you tried putting an onLongClickListener on your EditText? This won't let you add to the current list, but you can make your own dialog show up and then add all the options above, or some of them, or none of them and your own.
I'm not sure if exactly what you're asking for is possible, and if it is my way is a little bit more work, but you'll have full control.

ANDROID: I need to create a static menu at the top of the view (like Create, Edit)

I have a menu for about, exit.
But i need to create another static menu for options.
I will prefer to be at the top of the list that i have.
like:
Create, Edit
List
and when i press the menu button to open the (Exit,About).
If You can help, it will be perfect.
Thank you , have a good day.
Please see this post, and this one. The second post has nothing to do with what you want, it's just a nifty way to spruce up your UI by adding a QuickAction. The first post shows you how to build an "ActionBar" for Android.

ContextMenu with footer view (to add checkbox for 'make default' option)

Is there a standard way to add a footer to a context menu, in which I can add a checkbox to make the selected option the default one?
Similar to the context menu that comes up when choosing the default home screen for example.
From the Api docs for ContextMenu I see that you can set a header view, but not a footer view. Also the setCheckable / setGroupCheckable methods don't seem to help much here.
Does this need to be done via a custom (alert) dialog? I would be wondering if nobody has yet developed such a component yet in case it's not possible through the standard SDK api. Any standalone open source component out there (beside the Android source itself)?
The best I've come up with is using an AlertDialog
alert.getListView().addFooterView(...); and overriding it's onItemSelected method.

Categories

Resources