ontouchlistener
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
onTouchListener warning: onTouch should call View#performClick when a click is detected
Here you go: public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //some code…. break; case MotionEvent.ACTION_UP: v.performClick(); break; default: break; } return true; }
Android button has setOnTouchListener called on it but does not override performClick
This warning comes up because Android wants to remind you to think about the blind or visually impaired people who may be using your app. I suggest you watch this video for a quick overview about what that is like. The standard UI views (like Button, TextView, etc.) are all set up to provide blind … Read more
HorizontalScrollView within ScrollView Touch Handling
Update: I figured this out. On my ScrollView, I needed to override the onInterceptTouchEvent method to only intercept the touch event if the Y motion is > the X motion. It seems like the default behavior of a ScrollView is to intercept the touch event whenever there is ANY Y motion. So with the fix, … Read more