Voglio iniettare alcune viste da un layout xml a un RoboFragment ma sfortunatamente sto ricevendo Eccezione Nullpointer. Dato che RoboGuice (oltre ad essere un ottimo framework DI) ha pochissima documentazione, non so se posso usare @ContentView(R.layout.fragmentlayout)
per annotare il mio RoboFragment. C'è qualcosa che dovrei fare invece? Quello che attualmente faccio è:
InjectView in RoboFragment
public class TestFragment extends RoboFragment {
@InjectView(R.id.upBtn) private Button upBtn;
@Override
public View onCreateView(LayoutInflater layoutInflater,
ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(layoutInflater, container, savedInstanceState);
View view = layoutInflater.inflate(R.layout.fragmentlayout, container, false);
RoboGuice.getInjector(getActivity()).injectMembers(this);
upBtn.setSelected(false); // <------ Null pointer here
return view;
}
}
Spero che abbiate dato un'occhiata a queste due domande: http://stackoverflow.com/questions/9780769/android-roboguice-inject-views-on-fragment e http://stackoverflow.com/questions/8289660/ any-simple-examples-using-roboguice-with-fragments-in-android –
Sì. Il primo indica solo che l'iniezione avviene durante onViewCreated ma non riesco a capire come. Nel secondo ho anche provato RoboGuice.getInjector (getActivity()). InjectViewMembers (this); ma non è stato d'aiuto. –