質問

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!

役に立ちましたか?

解決

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");
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top