Inside the settouch interceptor unable to call the functions in android? - android

In my application I am using a popup window. For dismissing the popup window when the user touches outside, I am using the ORDER LIST PW CODING coding below, the pop window dismiss function works perfectly but not able to call
Submenu_listtask = new Submenu_list();
Submenu_listtask.execute();
this function inside setTouchInterceptor its not working. Can any one know please help me.
ORDER LIST PW CODING
order_list_pw.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
//Unable to call this function
Submenu_listtask = new Submenu_list();
Submenu_listtask.execute();
order_list_pw.dismiss();
Log.v("Name", "Name");
return true;
}
return false;
}
});

Return true at the end of onTouch() as returning false only enables you to catch ACTION_DOWN event

Related

I want to Disable the particular place for RecyclerTouchListener #onClick because I've button in that place and button.onClickListener also

I have a RecyclerViewClickListener.RecyclerTouchListener and on that #onClick override method, I sat Intent to go another activity.
But the problem is on that RecyclerViewClickListener.RecyclerTouchListener there is one image view also and I implemented onClickListener of that InmageView so that it will open one dialog box.
Now, when I click on that ImageView, 2 things happened at same time.
1.Opened Dialog box
2.It is going to another activity also, because of Intent.
How can I fix?
Try this
holder.hamburgerMenu.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP){
if (menuInterface != null) {
menuInterface.onClickHamburger(position);
}
return true;
}
return false;
}
});

want to do some task in editText.setOnTouchListener only once and not each time

i want to do something like when user click on editText then it gets enabled to be edit (by default it gets disabled in xml) and a toast(and some more buttons) should appear only once, not every time.
i create following logic for this:-
edt_title.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_UP == event.getAction()) {
Crouton.showText(ShowActivity.this, "Editing Mode Enabled",Style.INFO);
welcome.animate(getApplicationContext(), gallery, R.anim.fab_jump_from_down, 300);
edt_title.setFocusableInTouchMode(true);
}
return false;}
});
problem is that it gets called everytime when user tap on editText,
is there any way to do it only once when editText gets clicked.
May be it possible with use sharedPreference but it will be better if i can do it without using of sharedPreference.
Thanks in advance :)
Nishu
A simple solution would be:
edt_title.setOnTouchListener(new View.OnTouchListener() {
boolean called = false;
#Override
public boolean onTouch(View v, MotionEvent event) {
if (!called && MotionEvent.ACTION_UP == event.getAction()) {
Crouton.showText(ShowActivity.this, "Editing Mode Enabled",Style.INFO);
welcome.animate(getApplicationContext(), gallery, R.anim.fab_jump_from_down, 300);
edt_title.setFocusableInTouchMode(true);
called = true;
}
return false;
}
});
declare a global var that you use like flag and use for one simple time
boolean flagOneTime = true;
and add this inside your listener
if( flagOneTime )
{
// do something and disable flag
flagOneTime = false;
}

Android Dialog OnKeyUp (KeyEvent)?

I have a dialog and on in this dialog I have a button. When pressed search is suppose to appear. And this works completely fine.
BUT I want to able to set up OnKeyUp event so if the user clicks on the actual search button on the phone (not on the screen), search view appears.
I was able to do this in an activity this way:
public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
{
if (keyCode == Keycode.Search) {
// do something here
}
return base.OnKeyUp (keyCode, e);
}
But that's an override method. How do I call that for a Dialog?
This is how I've created the Dialog:
multiSelectDialog = new Dialog (context);
multiSelectDialog.RequestWindowFeature (1);
multiSelectDialog.SetContentView (dialogView);
multiSelectDialog.Show ();
Dialog has the OnKeyUp property.
multiSelectDialog.OnKeyUp(KeyCode.Search, KeyEvent e);
But I am not sure how to create a KeyEvent.
Thank you for your time.
onKeyUp() is a callback on Dialog, it will be called on a key-up event, you don't call it yourself.
Instead you have to extend Dialog and override onKeyUp(), for example:
multiSelectDialog = new Dialog(context) {
#Override
public boolean onKeyUp (int keyCode, KeyEvent event) {
// do something here
return true; // or false, depending on what you want to do
}
};
multiSelectDialog.requestWindowFeature(1);
multiSelectDialog.setContentView(dialogView);
multiSelectDialog.show();

Why getAction method always return ACTION_DOWN?

I am using onTouchListener for a layout. I want to take the click outside the layout. I set onTouchListetener for the layout. But motion event always shows ACTION_DOWN. Even i touchOutside the view, It is not showing ACTION_OUTSIDE. Could anyone help me to find out why it is not showing constant ACTION_OUTSIDE. Here is the code i am using
Layout.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
Log.i("action",event.getAction()+"");
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
Toast.makeText(getApplicationContext(), "check", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
If you return false, then you're signifying that you do not wish to receive further touch events. You need to return true to continue getting motion events.
Very simple to fix by adding this:
override fun onTouchEvent(event: MotionEvent): Boolean {
return true
}
The event listener itself listens to one event action at a time. The first of course is the ACTION.DOWN, in which your toast shows.
Just like what Jason Robinson and user936414, you have to return it to true so that the object or the listener could here the second event action, ACTION.OUTSIDE.
You will get ACTION_OUTSIDE when the touch is outside the activity and the flag FLAG_WATCH_OUTSIDE_TOUCH is set. Refer http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_WATCH_OUTSIDE_TOUCH

How to unsubscribe from onTouch() event

When application is started I run a custom pop-up till a user touches the screen. When screen is touched I catch it with event onTouch() and cancel the pop-up. From this point I don't need the event anymore.
The problem is the event is alive and continues to jump up every time a user touches the screen.
Is there any way to unsubscribe from this event? Something like in c# -= eventName.
The code is below:
#Override
public boolean onTouch(View v, MotionEvent event) {
if (!_stopToast)
{
_hintToast.cancel();
_stopToast = true;
}
return false;
}
There's no such method (lets say removeTouchListener or similar) which will help you to remove an already defined touch listener from a view. Setting null to setOnTouchListener won't help too. What you can do is to create a new object reference of OnTouchListener class which does nothing and set it in setOnTouchListener. For example:
public final OnTouchListener dummyOnTouchListener = new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent rawEvent) {
return false;
}
};
And simply use it as below:
yourView.setOnTouchListener(dummyOnTouchListener);

Categories

Resources