So I have different layouts for this one action.
And I have different classes, each of which is open and does its job with the layout.
I embed these classes in Activity via @Inject. All this without any problems.
But when I try to use @InjectView on one of the controls that are in the inactive layout, I get an error.
11-02 19: 17: 31.086: ERROR / AndroidRuntime (1326): called: java.lang.NullPointerException: cannot enter a null value in the be.baes.notes.View.EditNoteImpl.saveButton class when the field is not @Nullable
Then it will be a code.
public class EditNoteImpl implements EditNote { @Inject CancelEditNoteClickListener cancelEditNoteClickListener; @Inject SaveNoteClickListener saveNoteClickListener; @Inject Provider<Activity> activity; @InjectView(R.id.saveButton) Button saveButton; @Override public void activateEditNote() { activity.get().setContentView(R.layout.editnote); this.saveButton.setOnClickListener(saveNoteClickListener); } }
However, I can do it.
public class EditNoteImpl implements EditNote { @Inject CancelEditNoteClickListener cancelEditNoteClickListener; @Inject SaveNoteClickListener saveNoteClickListener; @Inject Provider<Activity> activity; private Button saveButton; @Override public void activateEditNote() { activity.get().setContentView(R.layout.editnote); saveButton = (Button)activity.get().findViewById(R.id.saveButton); this.saveButton.setOnClickListener(saveNoteClickListener); } }
Is there a better way to do this?
android roboguice
chrissie1
source share