这是我的xml。我把文本视图(标题)和列表视图放在那里。 我想用其他片段替换它。
<LinearLayout
android:id="@+id/stam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/moreDetails"
android:textSize="20sp"
android:textColor="#000000"/>
<ListView
android:id="@+id/books"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
在课堂上我做了这个覆盖功能:
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
Toast.makeText(this, "yeeeeeeee", Toast.LENGTH_LONG).show();
final Fragment fragment = new SearchBookFragment();
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.stam, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
显示吐司但视图未被替换。