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.

@OptionsItem for android.R.id.home causes lint error #1981

Description

@ened

AndroidAnnotations version:

4.2.0

Android compile SDK version:

Support libs: 25.3.0

Annotated code:

    @OptionsItem(android.R.id.home)
    void homeClicked() {
        finish();
    }

Expected generated code:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId_ = item.getItemId();
        if (itemId_ == android.R.id.home) {
            homeClicked();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

Actual generated code:

    import android.R;

    ...

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId_ = item.getItemId();
        if (itemId_ == R.id.home) {
            homeClicked();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

lint warning:

Don't include android.R here; use a fully qualified name for each usage instead

Seems to be new in Android Tools 23.3.

(or maybe I shouldn't listen for that button at all! 😄)

Activity

  1. WonderCsabo commented on Mar 18, 2017

    @WonderCsabo
    Member

    Yes, it is indeed not a good practice to import the Android R class. Unfortunately we do not exactly control how imports are made, our code generator does. But i opened a feature request for this. phax/jcodemodel#51

    Until this is fixed, you can set LINT in the lint.xml file, to ignore errors in the generated files:

    <?xml version="1.0" encoding="UTF-8"?>
    <lint>
        <issue id="all">
            <ignore regexp="build/generated/source/apt/.*"/>
        </issue>
    </lint>
  2. self-assigned this
    on Oct 30, 2017
  3. added a commit that references this issue on Oct 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions