0

使用时extends Fragment有效,但不适用于ListFragment.

主要活动:

public class FagTabHostMain extends FragmentActivity {
    FragmentTabHost mTabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_fag_tab_host_main);

            mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
            mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

            mTabHost.addTab(mTabHost.newTabSpec("more").setIndicator("More"),
                    More.class, null);

        } catch (Exception e) {
            Log.e("TAG", e.toString());
        }

    }

}

适用于以下:

public class More extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.more, null);
        return view;
    }
}

但不是:

public class More extends ListFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.more, null);
        return view;
    }
}
4

1 回答 1

1

在你R.layout.more必须是一个ListViewwithandroid:id="@android:id/list"标签,比如:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
于 2013-10-14T12:34:23.653 回答