私はフラグメントを持っており、ビューはonCreateViewのクラス変数に格納されています:
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;
}
ここでは両方とも非 Null であり、コードのどこでも変更されません。
後でこれは Main Activity から呼び出されます。
MainFragment frag = (MainFragment) mAdapter.getItem(mPager.getCurrentItem());
if(frag!=null) {
frag.onSecond();
}
そしてフラグメントで:
protected void onSecond(){
String left=times.getLeft();
if(countdown!=null)
countdown.setText(left);
}
onSecond では、mView とカウントダウンの両方が NULL になるのはなぜですか? 私はそれを説明することはできません。
メチン