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.

Multiple findViewById calls when setting listener for field #580

Closed

Description

@MikolajKakol

Code generated for settings listeners isn't the most efficient one. Sample generated code looks like that:

    private void afterSetContentView_() {
        myButton = ((Button) findViewById(id.button1));
        {
            View view = findViewById(id.button1);
            if (view!= null) {
                view.setOnClickListener(new OnClickListener() {


                    @Override
                    public void onClick(View view) {
                        PictureList_.this.button1();
                    }

                }
                );
            }
        }
    }

I'm guessing that is hard to know that myButton is the same button we are generating listener for. Maybe it would by good idea to replace findViewById method with some custom method that would use SparseArray to cache references?

Activity

  1. DayS commented on May 16, 2013

    @DayS
    Contributor

    This is a good idea, mostly on a complex ViewGroup with lots of View.

    I think, we can (and we should) do that directly at compile time. We just need to keep ViewByIdProcessor running before all other listeners processor.

    I'll take a look on this

  2. DayS commented on May 17, 2013

    @DayS
    Contributor

    I just see that the issue #552 is about the same thing.

  3. MikolajKakol commented on May 17, 2013

    @MikolajKakol
    Author

    Sorry for duplication, I searched for them but didn't find similar issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions