Unable to get @ViewById to work inside @EBean

@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 all good. So the view isdefinitely there. Also if I call this method from a retrofit callback 

(ie after a delay) the "name" is automatically populated.

I am using Android 3.3.2 annotations

+5
source share
2 answers

I do not know why this does not work, but if you need it, it is simple:

 @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"); } } 
+1
source

- Compliance with the above answer

Key -....

  @AfterViews void init() { previewButton.setText("Blah"); } 
  • this shows that the views are received, so you will not get a null pointer.
0
source

Source: https://habr.com/ru/post/1232525/


All Articles