5
  @EActivity(R.layout.data_layout) 
   public class MyActivity extendsActivity 
   {    
     @Bean    MyEbean bean;

      @AfterViews    
      public void setupView() 
      {
        bean.loadData("Test name");    
      } 
    }

   @EBean public class MyEbean 
   {    
     @RootContext    context;

      @ViewById(R.id.name_field)    
      TextView nameField;

     public void loadData(String name) 
     {
       nameField.setText(name);   
     } 
} 

"nameField" in loadData() is null. At the same time if I do this inside loadData()

nameField = (TextView)((Activity)context).findViewById(R.id.name_field);       it's all good. So the view isdefinitely there. Also if I call this method from a retrofit callback

(i.e. after a delay) "name" is auto populated.

I'm using Android Annotations 3.3.2

Query
  • 625
  • 1
  • 7
  • 22

2 Answers2

1

I don't know the reason why it doesn't work but if you need it just works, the solution is pretty easy:

@EActivity(R.layout.data_layout) 
public class MyActivity extends Activity {    
    @Bean    MyEbean bean; 
}

@EBean
public class MyEbean {
    @ViewById Button previewButton;

    @AfterViews void init() {
        previewButton.setText("Blah");
    }
}
Slava
  • 1,314
  • 14
  • 28
0

-Agree with above answer

The key point is ....

 @AfterViews void init() {
    previewButton.setText("Blah");
} 
  • this shows that views are fetched so you will not get null pointer .
Hardy
  • 2,576
  • 1
  • 23
  • 45