"how to repeat function on long click in android" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "how to repeat function on long click in android" answered properly. Developers are finding an appropriate answer about how to repeat function on long click in android related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like how to repeat function on long click in android. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on how to repeat function on long click in android. 

how to repeat function on long click in android

By StockholmStockholm on Dec 24, 2020
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, next one after the initialInterval, and subsequent
 * ones after the normalInterval.
 *
 * <p>Interval is scheduled after the onClick completes, so it has to run fast.
 * If it runs slow, it does not generate skipped onClicks. Can be rewritten to
 * achieve this.
 */
public class RepeatListener implements OnTouchListener {

    private Handler handler = new Handler();

    private int initialInterval;
    private final int normalInterval;
    private final OnClickListener clickListener;
    private View touchedView;

    private Runnable handlerRunnable = new Runnable() {
        @Override
        public void run() {
            if(touchedView.isEnabled()) {
                handler.postDelayed(this, normalInterval);
                clickListener.onClick(touchedView);
            } else {
                // if the view was disabled by the clickListener, remove the callback
                handler.removeCallbacks(handlerRunnable);
                touchedView.setPressed(false);
                touchedView = null;
            }
        }
    };

    /**
     * @param initialInterval The interval after first click event
     * @param normalInterval The interval after second and subsequent click 
     *       events
     * @param clickListener The OnClickListener, that will be called
     *       periodically
     */
    public RepeatListener(int initialInterval, int normalInterval, 
            OnClickListener clickListener) {
        if (clickListener == null)
            throw new IllegalArgumentException("null runnable");
        if (initialInterval < 0 || normalInterval < 0)
            throw new IllegalArgumentException("negative interval");

        this.initialInterval = initialInterval;
        this.normalInterval = normalInterval;
        this.clickListener = clickListener;
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
        case MotionEvent.ACTION_DOWN:
            handler.removeCallbacks(handlerRunnable);
            handler.postDelayed(handlerRunnable, initialInterval);
            touchedView = view;
            touchedView.setPressed(true);
            clickListener.onClick(view);
            return true;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            handler.removeCallbacks(handlerRunnable);
            touchedView.setPressed(false);
            touchedView = null;
            return true;
        }

        return false;
    }

}

Usage:

Button button = new Button(context);
button.setOnTouchListener(new RepeatListener(400, 100, new OnClickListener() {
  @Override
  public void onClick(View view) {
    // the code to execute repeatedly
  }
}));

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on how to repeat function on long click in android can get a collection of related answers to their query. Programmers need to enter their query on how to repeat function on long click in android related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to repeat function on long click in android for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of how to repeat function on long click in android while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "how to repeat function on long click in android". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to repeat function on long click in android resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "how to repeat function on long click in android"

View All Whatever queries

Whatever queries related to "how to repeat function on long click in android"

how to repeat function on long click in android long press gesture android aurelia repeat.for get index repeat kotlin we found a bug in the game i repeat repeat macro x times vim find repeat number using bitwise operator cron repeat every 5 minutes click effect on image button in android android play music on button click body on click function right click function in p5js $("button").click(function(){ $("div").slideToggle(); }); pyspark cast column to long check if users is from outside india using lat and long module can say how long your code took to run format date rails created long why does my chrome take so long to put up after update ameerpet lat long select select lat and long how long does it take for ethereum to transfer long task polus among us JERUsalem lat\long long query running script how long does wraith portal last how to display the long message on a standard ISPF screen ng build prod takes too long how long does t take for 3d game kit to IMPORT how long will it take to travel from earth to uranus 7.8 LAB: Double Helix All the Way (Long) how long has non binary been around timing how long key is pressed raspberry pi flutter requires android sdk 29 and the android buildtools 28.0.3 Execution failed for task ':app:processDebugResources'. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > Android resource linking failed capacitor build android without android studio android convert sensorEvent timestamp into unix timestamp android changing parent function states in child function which keyword is used to transfer control from a function back to the calling function in c Run a function called hello before you declare it. The function should simply print out "hello" Write a function definition of occurrences(text1, text2) that takes two string arguments. The function returns the number of times a character from the first argument occurs in the second argument. Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead. similar function like lazy function in pandera page required double click button Click Outside Close Menu Box right click display modal without button click click checkbox 1 to uncheck checkbox 2 print mouse click x and y To call any action method from the view on button click how to disable click inside iframe links and when you click on these link it will scroll the page to the respective section. arduino make led go up on button click bootstrap tooltip stay open after click on click scroll to div in center page matmenutriggerfor right click open iframe on button click power bi button click without ctrl detecting a click outside a button unity 2 sdl2 mouse click change images click div Change the button text to say "Click me to toggle a hidden secret!" and make the text toggle between fading in and out each time it is clicked. on click unmount the component tkinter add new element into grid by click v-data-table button inn row prevent row click input file selector on button click vuejs d3 toggle on click click unbind Update Status on click details ionic button active on click not make input box border on click pyqt double left click table row materialbuttontogglegroup uncheck on double click Hammer.JS desktop click and swipe conflict i want the dropdown to remain after click event one click both check add visual code when click right how to click on div to select radio button disable image dragging and right click CanDeactivate does not work if we click on cancel in the first time model d or model o click test move to click point raycast set popper click outside how to click on the datepicker date in jquery how to select right click option using selenium how to get a value on click of a link tag show and hide divs based on radio button click click.prevent swal go back to queue on click document click hide popup jquery button click event call url call two methods on button click To call any action method from the view on button click in mvc react click outside button click show next section i couldn't click my button when i resize my screen whenever a user clicks on the button that says "Click me", the number of times that button is clicked o onbackpressed android android recyclerview bottom padding view binding in android what is error make sure you have android development environment set up findview by id in android install android sdk placeholder android studio enable view binding android android process is waiting for debugger to attach spinner android android textview multiple font size no target device found android studio android navigation drawer menu item color ionic getting automatic disable dark mode on android table layout android studio android.content.res.Resources$NotFoundException: String resource ID #0x0 download android studio button style android studio picasso android not working snackbar gravity android Could not initialize class com.android.sdklib.repository.AndroidSdkHandler set dart sdk from android studio android translate animation values A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > java.lang.OutOfMemoryError (no error message) chnage hex color to int color in android ionic capacitor build android apk command clean build in android studio dexter android atic interface methods are only supported starting with Android N (--min-api 24): void butterknife.Unbinder.lambda$static$0()] android sdk location mac android studio string new line android studio turn off screen rotation enable vector drawable android android foreach how to get app package and app activity in android android moshi retrofit android searchview in toolbar hyperlink in android get incoming call number android example how to use font awesome icons in android chrome inspect android http/1.1 404 not found how to check and uncheck single radio button in android making Log in android viewmodelscope android android how to get width of widows android picasso proguard android disable app admin in adb how to remove empty white space around an imageview in android Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior android studio kotlin acces text from text view setdrawableTint of textview programmatically android unity android back button set title color in support action bar android android studio delete text file command failed with EACCES android change font programmatically android remove initial focus in edit text in android custom android how to read the crash report of android app imageview on background android android studio repeatable radio button android:inputType corresponding method handler 'public void onclick(android.view.view)' not found android foreach loop firestore geopoint query example in android custom progressdialog android is android studio open source run flutter app on real android device unit testing in android button android stdui android { lintOptions { checkReleaseBuilds false abortOnError false } } force update check playstore popup android How to create a video file path on Android 10 Constants.statusBarHeight not working on android notification icon badge android how many ways to pass data in android material design registration page in xml android otp view android studio scroll textview android android studio random number between 1 and 10 button size minimize in android android not have focus ob start material motion android navigation arch android tablet resource folder como llamar un recurso en layouut android studio wrap code in android studio flutter matterial button with icon only android android studio table row colspan how to make full screen app in notch mobile in android studio How to change the “recent apps tray” icon on android? dev android forloop android change time zone using adb notificacion toasr en android best podcast app for android type mismatch: requierd editable found string? in EditText Android Camera Permission in Android pixel to dp android android recyclerview disable auto scroll Android Number Picker format JAVA android studio 4 app crashes using gridlayout compare distance between two coordinates android android.permission.INTERACT_ACROSS_USERS_FULL

Browse Other Code Languages

CodeProZone