Android:片段无片段ID的视图

时间:2014-03-19 17:28:18

标签: android-fragments android-actionbar

我正在尝试实施操作栏标签,在此期间我在实现片段类时遇到错误。

public class fragmentImplement extends Fragment 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.fragment_layout);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_layout, container, false);
    }
}

XML文件是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView android:id="@+id/textView1"
    android:text="Fragment A"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>


</LinearLayout>

请帮助我,因为我变得非常沮丧

1 个答案:

答案 0 :(得分:0)

请在下次提供更多信息(哪个错误和哪些地方等)。

要使用Fragment,您还需要FragmentActivityFragment是可重复使用的组件,您可以在FragmentActivity中使用。

请使用此tutorial作为使用Fragment的起点,然后再往前走一步,查看this文章。

据我记得,Android SDK中还有一个示例,其中ActionBar带有标签。