Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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.

Optimisation: Remove doubled findViewById calls #1501

Copy link
Copy link
@ened

Description

@ened
Issue body actions

Given I have a class like this:

@EFragment
public class VolumeDialog extends DialogFragment {
    @ViewById
    SeekBar volumeSeekBar;

    @SeekBarProgressChange
    protected void volumeSeekBar(final int progress, final boolean fromUser) {
    }
}

Then AA generates code like this:

public final class VolumeDialog_
    extends com.company.VolumeDialog
    implements HasViews, OnViewChangedListener
{
    @Override
    public void onViewChanged(HasViews hasViews) {
        volumeSeekBar = ((SeekBar) hasViews.findViewById(com.company.R.id.volumeSeekBar));
        {
            final SeekBar view = ((SeekBar) hasViews.findViewById(com.company.R.id.volumeSeekBar));
            if (view!= null) {
                view.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {


                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        VolumeDialog_.this.volumeSeekBar(progress, fromUser);
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                }
                );
            }
        }
    }       
}

Which then causes lint to display this message:

The id com.company.R.id.volumeSeekBar has already been looked up in this method; possible cut & paste error?

Would it be sensible to keep a list of already looked up (& bound) members and then re-use them during processing stage?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.