ontouchlistener
Kotlin OnTouchListener called but it does not override performClick
Try this way : next.setOnTouchListener(object : View.OnTouchListener { override fun onTouch(v: View?, event: MotionEvent?): Boolean { when (event?.action) { MotionEvent.ACTION_DOWN -> //Do Something } return v?.onTouchEvent(event) ?: true } })
Can’t handle both click and touch events simultaneously
Its a little tricky. If you set onTouchListener you need to return true in ACTION_DOWN, to tell the system that I have consumed the event and it won’t trickle down to other listeners. But then OnClickListener won’t be fired. So you might think, I will just do my thing there and return false so I … Read more
Using BottomSheetBehavior with a inner CoordinatorLayout
I have finally released my implementation. Find it on Github or directly from jcenter: compile ‘com.otaliastudios:bottomsheetcoordinatorlayout:1.0.0’ All you have to do is using BottomSheetCoordinatorLayout as the root view for your bottom sheet. It will automatically inflate a working behavior for itself, so don’t worry about it. I have been using this for a long time … Read more
How to handle Touch Events on a Fragment?
I’m not sure if I understood your problem, but I will try to answer this. So to get touch events on fragment I would do this: -in your fragment onCreateView: View view = inflater.inflate(R.layout.fragment_test, container, false); view.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_MOVE){ //do something } return true; } … Read more
onTouchevent() vs onTouch()
Yes you are correct – onTouch() is used by users of the View to get touch events while onTouchEvent() is used by derived classes of the View to get touch events.
EditText in Listview loses focus when pressed on Android 4.x
A classic hack for situations like this is to use a handler and postDelayed(). In your adapter: private int lastFocussedPosition = -1; private Handler handler = new Handler(); public View getView(final int position, View convertView, ViewGroup parent) { // … edittext.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { handler.postDelayed(new … Read more
Android – Hold Button to Repeat Action
This is more independent implementation, usable with any View, that supports touch event: import android.os.Handler; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; /** * A class, that can be used as a TouchListener on any view (e.g. a Button). * It cyclically runs a clickListener, emulating keyboard-like behaviour. First * click is fired immediately, … Read more