I am replacing the existing fragment with new fragment and i am able to see my view but while setting on click listener on the button it returns null . I get the following e
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view = inflater.inflate(R.layout.capture_card_phone_number, container, false);
mPhone = (AutoCompleteTextView) getActivity().findViewById(R.id.phone_number);
Button next = (Button) view.findViewById(R.id.capture_phone_next);
next.setOnClickListener(this);
return view;
You have to call findViewById on your view - not on your activity.
The reason is that in onCreateView the View of Fragment is not created yet, so it is returning null. Try to do it in onResume and it will return you the view:
@Override
public void onResume() {
super.onResume();
mPhone = (AutoCompleteTextView) getActivity().findViewById(R.id.phone_number);
Button next = (Button) getActivity().findViewById(R.id.capture_phone_next);
next.setOnClickListener(this);
}