I am working on a Listfragment inside an activity. I have a nested class in an activity.
public static class DummySectionFragment extends ListFragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View contentView=inflater.inflate(R.layout.activity_main_fragment_browse, container);
return contentView;
}
but the compiler complain the DummySectionFragemt is not a fragment
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, show the tab contents in the
// container view.
Fragment fragment = new DummySectionFragment(); // <-- complain not fragment
// codes omitted .......
}
Complain from compiler: Type mismatch: cannot convert from MainActivity.DummySectionFragment to Fragment
When I make the DummySectionFragment directly extends Fragment, then it works, but I just do not understand why it do not work previously. Apparently, DummySectionFragment extends ListFragment which extends Fragment.It should be an implicit upcast here, I do not understand why it does not work:(
//make it directly extends Fragment -->
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View contentView=inflater.inflate(R.layout.activity_main_fragment_browse, container);
return contentView;
}