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.
Related
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
I have a list of web address display in a ListView. Each item of ListView have a TextView and an ImageView. TextView have attribute autolink="web".
I also have event: onItemLongClick in this ListView to open details of each others. But when I do long click event on each item in list, they do open new page also open browser with link website in TextView.
How can I set when onItemLongClick, the TextView can't click into link? I try set TextView.setLinkClickable(false) but it isn't working.
Many thanks
You can achieve what you want in this way.
on your .xml, add this to the TextView :
TextView
...
android:autoLink="web"
android:textIsSelectable="true"
on your code use ListView click behavior and longClick behavior.
In your onItemLongClick() method, return true to indicate that you have consumed the click event and it should not be passed on to any other listeners.
According to the docs, the return value is described as -
boolean true if the callback consumed the long click, false otherwise
Returning true will NOT pass the long click event, which is also a click event, to the OnItemClickListener.
U can try Using :-
Linkify.addLinks(txtView, Linkify.ALL);
I am trying to cope with one (seemed to be) smalll thing. In my app I've got one activity with two EditText fields.
I want one of them to be normall field (etNormal), and the other (etButton) behave more like button, so when you touch it, the keybord is not shown but instead the sliding drawer is opened. If sliding drawer is opened and you will press the normall edittext sliding drawer will hide.
I've tried adding OnClickListener and OnTouchListener (not in same tries) to both with condition if etButton was clicked/touched open sliding drawer, if not then close.
The outcome was strange. When it was OnTouchListener test it was more like toggle, so when I pressed one drawer opens and on another close. When it came to OnClickListener I needed to press each edtitext twice to get action done.
And to hide keybord in etButton I am using setInputType(InputType.TYPE_NULL);. I've tried also setEnabled(false); but then I was even unable to click/touch it. The one defect of currently used method is when I am changing click from etNormal to etButton, the keyboard is still shown and it doesn't hide.
So, can anyone tell me what I can do to achive my goal?
EDIT:
I've erad your current suggestions and modified a little my code, but still it is not working.
This is a part of it where I am assigning OnTouchListener:
OnTouchListener touchListener = new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent ev) {
if(v==etButton && ev.getAction()==MotionEvent.ACTION_DOWN) {
slidingDrawer.animateOpen();
}else {
slidingDrawer.animateClose();
}
return false;
}
};
etNormal1.setOnTouchListener(touchListener);
etNormal2.setOnTouchListener(touchListener);
etButton.setOnTouchListener(touchListener);
Also in etButton declaration in XML layout file I have:
android:focusable="false"
But now, on etButton touch nothing hapens (only sliding drawer hides if was opened), and when etNormal1 or 2 is touched sliding drawer shows up or hides depending what was first (in other words toggel).
Any idea, what is wrong here?
Got an editText working like that with
android:focusable="false"
android:clickable="true"
Then an OnClickListener to override the action
In addition to above answers, I hide cursor using cursorVisibility!
android:focusable="false"
android:clickable="true"
android:cursorVisible="false"
android:focusableInTouchMode="false"
cursorVisible To show/hide the cursor on clicking the EditText
focusable To gain focus when user is touching the view, like EditText
focusableInTouchMode To keep a view selected. (select and click are different)
For detailed understanding, refer here
In your layout, add the following attribute to the EditText
android:focusable="false"
android:focusableInTouchMode="false"
Next, write method to handle the click on the EditText and add your application logic .
If you are using onTouch event, when you click the edittext, you will get two events with action as MotionEvent.Action_down and action Up. so basically it will give the effect of clicking the edit text twice. can you please provide the code so that we can have a deep look.
ReWrite your code as :
OnTouchListener touchListener = new OnTouchListener() {
boolean isOpen=false;
#Override
public boolean onTouch(View v, MotionEvent ev) {
if(v==etButton && ev.getAction()==MotionEvent.ACTION_UP) {
if(!isOpen){
slidingDrawer.animateOpen();
}else{
slidingDrawer.animateClose();
}
isOpen=!isOpen;
}
return false;
}
};
If etButton needs to be an EditText (why not a button, if it should behave like one?), maybe you could set an onFocusChangeListener. Once it gets the focus, you can show the drawer...?
Not sure about not showing the keyboard...
EditTexts are tricky. The reason why you have to press twice when you have use an OnClickListener is that the first time around the EditText gets focus and this consumes the touch event, in that case the OnFocusListener is triggered. When you touch the second time, the EditText already has Focus so now a click event is triggered.
I would suggest you try to do this without EditTexts. That would in any case yield a cleaner and simpler solution. Why exactly do you want to use EditTexts instead of Buttons?
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.
Is there a way to programmatically deselect/wipe whatever the user has selected with the trackball/trackpad?
When I hit the back button on an Activity, the Activity it falls back to has a button that is selected as if the user had used the trackball/pad. I'm not sure what is selected on the previous Activity, but obviously something is. I'd like to programmatically wipe any selection just before the Activity finishes.
Looking through the JavaDoc for View I see a number of focus-related functions.
void clearFocus(); // drop focus from this view.
View findFocus(); // finds a view that is a child of this view that has focus, if any
View focusSearch(int dir); // finds the next view that can take focus in the given direction
void requestFocus
Sounds like findFocus().clearFocus() should do the trick (unless findFocus happens to return null)... you just need a handle to the other activity's View... which shouldn't be too hard if it's your code, or Non Trivial if it isn't.
If it IS your code, it seems like you could just add a clearFocus() to the button's onClickHandler.