How to disable long click on XWalkView (Crosswalk Project) in Android - android

It does not work.
setLongClickable(true);
setOnLongClickListener(new OnLongClickListener()..

Set OnLongClickListener and override onLongClick. By returning true, the long click event will be treated as consumed.
mWebView.setOnLongClickListener(new View.OnLongClickListener(){
#Override
public boolean onLongClick(View v) {
return true;
}
});

Related

how to hide Text selection handle from webview : android

i have a custom webview on which user can select text, i want to hide the "TEXT SELECTION HANDLES" when user click on some button at the bottom , i want the text to be selected but want to hide the handles, as you can see below :
// call hideTextSelection() from your onCreate()
function hideTextSelection(){
//SOLUTION 1-> vibration caused by the long click not works here
webView.setHapticFeedbackEnabled(false);
//Solution 2:
/*webView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
return true;
}
});
webView.setLongClickable(false);*/
}
// whenever you wants to select the data ie. after onClicking the button 'from the bottom of your UI', make it to select as below
yourBottomButton.setOnClickListener(new OnClickListener() {
#Override
public boolean onClick(View v) {
webView.setHapticFeedbackEnabled(true);
}
});
Try this
mWebView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
return true;
}
});
mWebView.setLongClickable(false);

Why can't we write public boolean onClick(View v) like we write public boolean onLongClick(View v)

When we write the method for Long Click we write as -
public boolean onLongClick(View v){
return true;
}
I know the reason behind why we write it as boolean, my query is why can't we also write
public boolean onClick(View v){
return true;
}
why does making onCLick a Boolean give me an error?
because the onClick method doesn't return any value. You don't need to write return operator for the onClick method.

Android - How to stop Linkify on Long-Press?

I am working on my project where I have a listView and each item is a LinaerLayout that has a TextView with Linkify hyperlink.
So, when I press the an item in the List view, it opens a dialog, which is fine.
When I press the linked text in the listView, it opens a dialog, which is fine.
PROBLEM: When I LONG-PRESS the linked text in the Listview, it opens a dialog AND an activity of the given link at the same time! In this case, I only want it to open the dialog only.
In other words, I want to ignore Linkify's hyperlink on Long press.
Does anyone know how I can do this?
I don't know where to apply LongPress attributs... Thanks in advance.
FYI, I tried the following but doesn't work.
public class URLSpanNoUnderline extends URLSpan implements OnLongClickListener {
public URLSpanNoUnderline(String url) {
super(url);
}
#Override
public void updateDrawState(TextPaint textPaint) {
super.updateDrawState(textPaint);
textPaint.setUnderlineText(false);
}
#Override
public void onClick(View v) {}
#Override
public boolean onLongClick(View v) {
Log.d("log", "lonnnnnnnnnnnnnnnng click");
return false;
}
}
you need a longClick mark,set it when in textview longclicklistener,and in touchlistener,when action equals MotionEvent.ACTION_UP and longClick is true,return true。
textview.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
isLongClick= true;
return false;
}
});
textview.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP && isLongClick){
isLongClick= false;
return true;
}
if(event.getAction() == MotionEvent.ACTION_DOWN){
isLongClick= false;
}
return v.onTouchEvent(event);
}
});
this problem happend in some phone.

Close event for longClick menu in android

In my android app I need to do some actions after close longClick menu.
I have the next code:
editText.setOnLongClickListener(new View.OnLongClickListener()
{
#Override
public boolean onLongClick (View v)
{
flag = "On";
return false;
}
});
And it works fine, but I need flag="Off" when longClick menu will be closed. Is it possible to catch this event?
Thank you!
you should use this:
#Override
public void onOptionsMenuClosed(Menu menu) {
flag = "off";
super.onOptionsMenuClosed(menu);
}

How to prevent button onClick firing repeatly?

I have a Button which sets both onLongClickListener & onClickListener :
onLongClickListener :
#Override
public boolean onLongClick(View v) {
do something ...
return true;
}
onClickListener :
#Override
public void onClick(View v) {
do something else ...
}
When I long click the button, onLongClick fires repeatly
(sometimes onClick fires too when I release the button, it's weird ##")
What I want is to make the onLongClick be triggered only once for one long press.
So I modified the code :
onLongClickListener :
#Override
public boolean onLongClick(View v) {
do something ...
myButton.setLongClickable(false);
return true;
}
onClickListener :
#Override
public void onClick(View v) {
myButton.setLongClickable(true);
do something else ...
}
Unfortunately, the onClick callback was locked too after onLongClick fires!
I cant unlock the button anymore :|
Whats wrong with my code? Also, why onClick sometimes works when I release my button after a long click?
I've got the code you need, give me a minute to post it.
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//DO STUFF GRAH!
}
});
btn.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
//OTHER STUFF
return true;
}
});
This worked fine for me. I made an int and onLongClick added one and displayed it in a toast. Always incremented by one, and didn't do the onClick (reset it to 0).

Categories

Resources