0

I like the convenience of android:onClick, which allows you to set up a click listener on a view simply by assigning a pre-defined style including:

<item name="android:onClick">myOnClickFunction</item>

If you also assign a unique android:tag to each view, then in myOnClickFunction() you can check the tag and customise the click functionality accordingly (or just do the same for each view).

My question is: is there an equivalent long click property (certainly 'android:onLongClick' doesn't exist), or is it a case of assigning a long click listener to each view separately via setOnLongClickListener()?

drmrbrewer
  • 11,491
  • 21
  • 85
  • 181
  • 1
    it's the latter. – RobCo May 06 '17 at 10:49
  • 1
    In this link http://stackoverflow.com/questions/5706038/long-press-definition-at-xml-layout-like-androidonclick-does read answer given by "Aleksander Gralak" it will give idea to you – Lingeshwaran May 06 '17 at 10:51
  • Why on earth don't they just add a native `android:onLongClick`? They obviously thought it a good idea to add `android:onClick` so why not `android:onLongClick` at the same time? – drmrbrewer May 06 '17 at 15:39

1 Answers1

1

I woud suggest you to take a look at data binding library.

This document explains how to use the Data Binding Library to write declarative layouts and minimize the glue code necessary to bind your application logic and layouts.

Farid
  • 1,024
  • 9
  • 16
  • Looks interesting but wouldn't really know where to start :-( – drmrbrewer May 06 '17 at 11:43
  • :-) I did, but I think I could understand it just as well if it had been written in Greek. I think I work better by seeing a simple example, like how this could be applied to a very simple case where you want to add a long click listener to a `TextView` via XML – drmrbrewer May 06 '17 at 11:49