Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Add support for custom listeners #167

Description

@dgknipp

There seems to be good support for onClick related listeners, but not UI elements that have custom listeners, (e.g. SeekBar.OnSeekBarChangeListener).

You could build a @Listener annotation that could take the id of a specific UI element and based on that element's type and the name of the method being annotated, infer what listener to bind.

The below example could delegate the onProgressChanged method of SeekBar.OnSeekBarChangeListener to the annotated class.

@Listener(R.id.mySeekBar)
public void onProgressChanged(...)

Activity

  1. pyricau commented on Apr 16, 2012

    @pyricau
    Contributor

    This is an interesting idea, however, it can't be done that way :) .

    • We cannot determine the type of a view based on its ID. Different views can have the same id, ids can be generated without any view associated with them in the xml, views can be added from the code, layouts can be set from the code, etc.
    • Even if we knew that R.id.mySeekBar is a SeekBar, it wouldn't be easy to find the corresponding listener: you'd have to list all methods and parent methods of the activity, trying to find a "setXXX" that has a param with the corresponding type:
      • Won't work with @EBean
      • Sometimes it may be addXXX instead of setXXX
      • You might as well find two methods with different names and the same param type
    • There's a convention in AA where the method name is used as id is no id is given. It would clearly not work here
    • We'd have to match the exact signature (eg void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)), because of overloading (two methods may have the same name), but then we'd lost the advantage of not defining some params.

    If you or someone else comes up with other ideas on how to do that, please tell :) . In the meantime, I guess the best fix we can have for now is to provide a SeekBar event dedicated annotation.

  2. mathieuboniface commented on May 1, 2012

    @mathieuboniface
    Contributor

    As we have no answer since 15 days, I close that issue.

    I will create a new issue to provide a new annotation for handling SeekBar.OnSeekBarChangeListener events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions