Mam fragment, który muszę wyświetlić na ekranie. Chcę móc używać InjectView
do wstrzykiwania moich elementów interfejsu użytkownika. InjectView działa dobrze na działaniach, ponieważ widok (xml) jest ustawiony podczas onCreate
, jednak w przypadku fragmentów widok jest ustawiony na onCreatView
.Android i RoboGuice - Inject widoki fragmentu?
Czy istnieje sposób użycia InjectView na fragmentach? Wiem, że mogę używać findViewbyId znaleźć każdy element, ale raczej użyć InjectView
public class ProfileFragment extends RoboDialogFragment {
@InjectView(R.id.commentEditText)
protected EditText commentEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I get a null pointer exception here
commentEditText.setText("Some comment");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profile , container, false);
// I get a null pointer exception here
commentEditText.setText("Some comment");
return view;
}
}
Proszę gwiazda problem Roboguice (http://code.google.com/ p/roboguice/issues/detail? id = 160 & q = contentview), aby pokazać programistom, że to powinno być dodane – Diederik