excilys/androidannotations — Issue #21: Warnings with OnXXXListeners in @EViewGroup generated subclasses
Author: pyricau
Created: 2012-01-06 11:05:52+00:00
State: open

Warnings with OnXXXListeners in @EViewGroup generated subclasses

Code example:

```
@EViewGroup(R.layout.component)
public class MyEnhancedLayout extends FrameLayout {

@Click
public void title() {
}

}
```

*****************
Generated code:

```
public final class BasicComponent_
extends BasicComponent
{

public BasicComponent_(Context context, int i) {
super(context, i);
}

private void afterSetContentView_() {

{
View view = findViewById(id.title);
if (view!= null) {
view.setOnClickListener(new OnClickListener() {

public void onClick(View view) {
title();
}

}
);
}
}
}

@Override
public void onFinishInflate() {
inflate(getContext(), layout.component, this);
afterSetContentView_();
super.onFinishInflate();
}

}
```

CodeModel adds an import to `import android.view.View.OnClickListener;` in the generated code. OnClickListener is an inner class of View, and since a ViewGroup extends View, this import is not needed, because OnClickListener is visible from any View subclass.

Therefore, we have the following warning in the generated class :

`The import android.view.View.OnClickListener is never used`

Same thing for `@LongClick`, `@Touch`, etc.

We'll have to dig through CodeModel source to see if we can do anything about that (maybe using reflection...), or if we should submit a patch to CodeModel.