我在做Android的應用程序,我想設置一些片段,但我每次啓動應用時它有兩個錯誤崩潰:Android的碎片誤差充氣類片段
MainActivity: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class fragment
[email protected] must implement OnFragmentInteractionListener
搜索互聯網,我發現了很多的固定他們的Android ::名字太類改變XML文件的人。我做到了,但仍然發生在我身上。
我使用此代碼導航到片段:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
Fragment fragment = new Fragment();
if (id == R.id.nav_camera) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.search_fragment, fragment);
ft.commit();
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
我的片段XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SearchFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
我在activity_main實現它:
<fragment android:id="@+id/search_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.onelio.app.SearchFragment"/>
哪有我修理它? 感謝