I have a list that uses a database to display some data. There are several operations that the user can perform on each list item and instead of implementing a context menu where the user uses a long press to bring up a list of possible operations I would like to add buttons to each item so the user can just tap the button and perform the operation. The list can be potentially large and attaching a listener to each button for each list item is overkill so I would like to do what Javascript programmers do with event bubbling, i.e. attach a single handler to a top level element like the entire list and let the click events bubble up to it. How would I go about doing this?
Android list tap event delegation
804 Views Asked by David K. At
1
There are 1 best solutions below
Related Questions in ANDROID
- Delay in loading Html Page(WebView) from assets folder in real android device
- MPAndroidChart method setWordWrapEnabled() not found
- Designing a 'new post' android activity
- Android :EditText inside ListView always update first item in the listview
- Android: Transferring Data via ContentIntent
- Wrong xml being inflated android
- AsyncTask Class
- Unable to receive extras in Android Intent
- Website zoomed out on Android default browser
- Square FloatingActionButton with Android Design Library
- Google Maps API Re-size
- Push toolbar content below statusbar
- Android FragmentPagerAdapter Circular listview
- Layout not shifting up when keyboard is open
- auDIO_OUTPUT_FLAG_FAST denied by client can't connect to localhost
Related Questions in LISTVIEW
- Android :EditText inside ListView always update first item in the listview
- Android FragmentPagerAdapter Circular listview
- dynamically inflating views into listView items. odd behaviour
- Button to save certain listview
- ListView: Image shift when using StateImageIndex
- Android Cannot disable listview header dividers
- Link button Delete from ListView and DB in C#
- Android: Empty textview for first item in a listview
- Android Studio cannot recognize "setAdapter()" method
- Open a webpage on list view click
- Need help linking listview to an ArrayAdapter error: Cannot resolve method'SetListAdapter(android.widget.ArrayAdapter<java.lang.String>)'
- How to set data context of ViewModela View's xaml?
- notifydataSetChanged working but only showing 1 result in listview Android
- How to change the contents of listview on item click?
- WPF: get my object after ListView context menu right click instead of item index
Related Questions in EVENT-HANDLING
- Unity3d - Input.GetKey returns true more than once
- Jquery selector - affecting element inside same DOM element
- Having issues using a scope in Jquery
- Detect if Application was suspended in OnNavigatedFrom for Windows Phone 8
- CasperJs Catch Timeout and Restart Process
- Portlet IPC after received Event
- Javascript : Replace Event Listener
- Multiple objects containing SerialPort with same SerialDataReceivedEventHandler
- After Creating a Control, automatically add it to specific panel
- C# Displaying String of ObservableCollection on event CollectionChanged
- check child check box by parent check box in jquery
- Execute a script on f:ajax "success" event only when validation has not failed
- Web Audio API- onended event scope
- Dynamically added event handler disables the previous one in JavaScript
- Attaching two functions to event handler
Related Questions in EVENT-DELEGATION
- How to use event delegation when using clipboardjs?
- Event Delegation, how to target a specific span inside a div
- Stop applying a certain class to a parent of an event target
- Backbone passing a view an event and unbinding it from parent view
- update querySelectorAll nodeList after added element dynamically
- Event delegation - dynamically generated content
- Closure event delegation - event listener on DOM parent that covers children/descendants of a given class
- jQuery Event Delegation for text input on change
- Bootstrap-confirmation not binding to dynamic elements?
- Event handling ideas
- Android list tap event delegation
- Does jQuery class selector event binding attach eventHandler to each instance?
- event delegation in Hammer JS multi-tocuh events not working
- jQuery live alternative (is there only on()?)
- Maintaining delegated event binding after removal of bound element(s)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
View.OnClickListener.onClick() does not bubble, so the solution you propose would not work.
OTOH, View.OnTouchListener.onTouch() does bubble so this could possibly be used, but it would require you to manually handle MotionEvent's down/up to detect a click.
Besides, if you create a lot of Buttons, than are you sure that adding onCLick handlers would be a lot of overhead, especially since you can register the same method for all of them.
What you are trying to do sounds like a premature optimization. Be sure there is real overhead affecting your users, before you try to deal with it.