Question

I've a helper class with one function, that receives an activity as a parameter. I want to inject a view from that activity. Is this possible?

public class myClass {
   public void myMethod(final Activity activity) {
      // Use here a TextView from that activity - how to inject it?

Thanks in advance!

Was it helpful?

Solution

Inject it as a field of the class. You can't inject directly into a method body.

public class myClass {
    @InjectView(R.id.myTextView)
    private TextView myTextView;
    public void myMethod(final Activity activity) {
        // Use here a TextView from that activity - how to inject it?
        myTextView.setText("something");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top