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

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

Closed
ened opened this issue Mar 17, 2017 · 1 comment
Closed

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

ened opened this issue Mar 17, 2017 · 1 comment
Assignees

Comments

@ened
Copy link
Contributor

ened commented Mar 17, 2017

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! 😄)

@WonderCsabo
Copy link
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>

@WonderCsabo WonderCsabo self-assigned this Oct 30, 2017
WonderCsabo added a commit to WonderCsabo/androidannotations that referenced this issue Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants