How to have a longPress Event on a CheckBox in Codenameone? - android

i need to implement a long press event on a checkbox in codenameone.
On normal buttons i use the longPointerPress method and a boolean to control if the short- or longpress event happens.
With the checkboxes i cannot find that option, it only toggles between checked/unchecked.
How is it possible to use a long press on a checkbox?
Thanks for your help!

I'm not familiar with codenameone, but in Android you can just use setOnLongClickListener since every View has that function.

longPress is a callback. You don't invoke it, you override it and it triggers when a longpress occurs. So Codename One invokes it internally. See the answer here: https://stackoverflow.com/a/54063388/756809

Related

How to make ontouchlistener work in such way it respond different when holding and when only touching?

I have a button , on which calling onTouchListener , I want to set different behavior . 1. if it is being pressed ,
2.when user just touch the button
You're probably better off using an OnLongClickListener rather than an onTouch. You can set one just like an onClick and it will call you when a press and hold has occurred.
If you did want to implement it via onTouch, you'd set a timer in the touchDown. If the user has a touchUp, cancel the timer. If not, when the timer goes off it is now a touch and hold and you perform whatever behavior you wanted to.

How to stop an event when i click on another, when both events going to same activity

I have two events both are going to same activity, if i click on one event and again click on another event it shows the same action.How to resolve this
In you are using views in order to trigger those events, then after clicking on the first view which triggers the event, you can disable the second view.
You didnt upload your code so I am guessing that in the implementation of of your listeners class you are referencing the same view and ofcourse it gives the same result no matter how many events you fire.

How to disable edittext pop up when EditText is LongClicked?

Hello All I have used onLongClickListener() to my EditText view but whenever I click on view for long time so a popup appears that doesn't let me do my task in onLongClick(View v).
The pop up contains some options like Select All,Select Text,Cut All ,Copy All etc.
I want to disable that (that should not appear on clicking long on EditText view).
How can I do that please Help Me
You can return true in your onLongClick listener onLongClick method that means you have consumed the event and it won't be passed further along.
I also got that popup when I overrode onTouchEvent() and returned false. Suppress it by returning true.

What's the difference between setOnClickListener() & setOnCheckedChangedListener() for checkbox?

What's the difference between setOnClickListener() & setOnCheckedChangedListener() for checkbox?
I am working with both listener but i could not find any difference,they both gives same answer.Please solve this query
thank you
regards
Ayudh
We use setOnClickListener() for Perform action on clicks, depending on whether it's now checked or not whereas setOnCheckedChangedListener() method used for checkbox change listener -- that is where we handle the changes in the checkbox state.
setOnClickListener() is a listener that can be used mostly with all kinds of view(widgets) for performing action on Click while setOnCheckedChangedListener() is used only to change the state of checkbox and radio buttons. You should prefer setOnCheckedChangedListener() for changing the state of checkbox and perform some action.
Google uses onClickListener in this tutorial, even when they manipulate widgets that support the change listener.

Android: show ContextMenu on longPress for a view?

I a view have for which I would like to show a ContextMenu on a longPress. I was able to get this ContextMenu to display using the recommended method of: calling activity.registerForContextmenu and overriding onCreateContextMenu(...).
However, I would like to do other things on other touch events, so my view has a TouchHandler assigned to it. When this touch handler is set, the onCreateContextMenu() never gets called (presumably because my TouchHandler is eating the longPress). So, is there anyway for me to instantiate and show a ContextMenu without the onCreateContenxtMenu() method being called?
Alternatively, I could just show my own custom dialog with my "menu" items. Is there any disadvantage to using a custom dialog instead of the ContextMenu?
One thing to try, is to return false from your OnTouchListener if you don't want the event to be consumed.
What do you return from OnTouchListener.OnTouch? Returning false means you haven't consumed the event, which should mean that other actions can be peformed on it as well.

Categories

Resources