Creating a custom event listener on an Android app

Define a callback interface public interface NewsUpdateListener { void onNewsUpdate(<News data to be passed>); } Provide a registration facility on the background thread which gets the RSS feed class <Background processing class name> { …. ArrayList<NewsUpdateListener> listeners = new ArrayList<NewsUpdateListener> (); …. public void setOnNewsUpdateListener (NewsUpdateListener listener) { // Store the listener object this.listeners.add(listener); } … Read more

Detect user scroll down or scroll up in jQuery [duplicate]

To differentiate between scroll up/down in jQuery, you could use: var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? “DOMMouseScroll” : “mousewheel” //FF doesn’t recognize mousewheel as of FF3.x $(‘#yourDiv’).bind(mousewheelevt, function(e){ var evt = window.event || e //equalize event object evt = evt.originalEvent ? evt.originalEvent : evt; //convert to originalEvent if possible var delta = evt.detail ? evt.detail*(-40) : … Read more

Add multiple window.onload events

Most of the “solutions” suggested are Microsoft-specific, or require bloated libraries. Here’s one good way. This works with W3C-compliant browsers and with Microsoft IE. if (window.addEventListener) // W3C standard { window.addEventListener(‘load’, myFunction, false); // NB **not** ‘onload’ } else if (window.attachEvent) // Microsoft { window.attachEvent(‘onload’, myFunction); }

Trigger an event when clipboard content changes

Have you thought about using an endless loop and “sleeping” between tries? I used pyperclip for a simple PoC and it worked like a charm, and Windows and Linux. import time import sys import os import pyperclip recent_value = “” while True: tmp_value = pyperclip.paste() if tmp_value != recent_value: recent_value = tmp_value print(“Value changed: %s” … Read more

C# event debounce

I’ve used this to debounce events with some success: public static Action<T> Debounce<T>(this Action<T> func, int milliseconds = 300) { var last = 0; return arg => { var current = Interlocked.Increment(ref last); Task.Delay(milliseconds).ContinueWith(task => { if (current == last) func(arg); task.Dispose(); }); }; } Usage Action<int> a = (arg) => { // This was … Read more

How can I remove a JavaScript event listener?

You need to use named functions. Also, the click variable needs to be outside the handler to increment. var click_count = 0; function myClick(event) { click_count++; if(click_count == 50) { // to remove canvas.removeEventListener(‘click’, myClick); } } // to add canvas.addEventListener(‘click’, myClick); You could close around the click_counter variable like this: var myClick = (function( … Read more

Force server TextChanged event from javascript

Way 1: function DoPostBack() { __doPostBack(“txt_sssn_dt”, “TextChanged”); } Calling ASP.NET server-side events using JavaScript Way 2: Calling Server Side function from Client Side Script Way 3: one of the way to set focus lost like this function texboxchange() { var txtBox = document.getElementById(‘<%= TextBox4.ClientID %>’); var count = txtBox.value.length; if (count == 2) { document.getElementById(‘<%= … Read more