met*_*e38 1 java null android fragment android-activity
我有一个片段,视图存储在onCreateView中的一个Class变量中:
private FrameLayout mView;
private TextView countdown;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle bdl) {
mView = (FrameLayout)inflater.inflate(R.layout.vakit_fragment, container, false);
countdown = (TextView) mView.findViewById(R.id.countdown);
...
return mView;
}
Run Code Online (Sandbox Code Playgroud)
这两个都是非空的,不会在我的代码中的任何地方修改.
以后这是从主要活动调用的:
MainFragment frag = (MainFragment) mAdapter.getItem(mPager.getCurrentItem());
if(frag!=null) {
frag.onSecond();
}
Run Code Online (Sandbox Code Playgroud)
在片段中:
protected void onSecond(){
String left=times.getLeft();
if(countdown!=null)
countdown.setText(left);
}
Run Code Online (Sandbox Code Playgroud)
在onSecond上,mView和countdown都是NULL,为什么?我无法解释.
倚天
| 归档时间: |
|
| 查看次数: |
2809 次 |
| 最近记录: |