there is default constructor in fragment, i want to know that what it's use and what functionality it provides? and i run the code without it it worked perfectly and i can't find any error in removing it
public class SongListFragment extends Fragment {
private static final String SONG_IDS = "song_ids";
// TODO: Rename and change types of parameters
private int[] songIds;
private OnFragmentInteractionListener mListener;
public SongListFragment() {
// Required empty public constructor
}
// TODO: Rename and change types and number of parameters
public static SongListFragment newInstance(int[] songIds) {
SongListFragment fragment = new SongListFragment();
Bundle args = new Bundle();
args.putIntArray(SONG_IDS, songIds);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
songIds = getArguments().getIntArray(SONG_IDS);
}
}
@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState )
{
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_song_list, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onSongSelected(10);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
}
else {
throw new RuntimeException( context.toString() +
" must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
public void onSongSelected(int songId);
}
}