我想知道这个对象在这里显示为空指针的问题。请澄清我。
这是我的代码:
public class HomeFragment extends Fragment {
int mFlipping = 0 ; // Initially flipping is off
Button mButton ;
public HomeFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
ViewFlipper flipper = (ViewFlipper) getActivity().findViewById(R.id.flipper1);
if (mFlipping == 0) {
/** Start Flipping */
flipper.startFlipping();
mFlipping = 1;
mButton.setText(R.string.str_btn_stop);
} else {
/** Stop Flipping */
flipper.stopFlipping();
mFlipping = 0;
mButton.setText(R.string.str_btn_start);
}
}
};
/** Getting a reference to the button available in the resource */
mButton = (Button) getActivity().findViewById(R.id.btn);
/** Setting click event listner for the button */
mButton.setOnClickListener(listener);
return rootView;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main, menu);
super.onCreateOptionsMenu(menu, inflater);
}
}