【发布时间】:2012-04-04 13:32:10
【问题描述】:
我有一个片段需要在屏幕上显示。我希望能够使用InjectView 来注入我的 UI 元素。 InjectView 在活动上运行良好,因为视图 (xml) 是在 onCreate 期间设置的,但是在片段上,视图是在 onCreatView 上设置的。
那么有没有办法在片段上使用 InjectView 呢?我知道我可以使用 findViewbyId 来查找每个元素,但我更愿意使用 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;
}
}
【问题讨论】:
-
请为 Roboguice 问题 (code.google.com/p/roboguice/issues/…) 加注星标,向开发人员展示应该添加的内容
标签: android fragment inject roboguice