ary*_*axt 15 android inject fragment roboguice
我有一个片段,我需要在屏幕上显示.我希望能够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;
}
}
Run Code Online (Sandbox Code Playgroud)
ary*_*axt 27
注射发生在 onViewCreated
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
commentEditText.setText("Some comment");
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8183 次 |
最近记录: |