我尝试创建我的幻灯片menu.wrote代码女巫可以显示/隐藏幻灯片菜单,但现在我想在listview中点击监听器替换片段。当我点击listview时,我无法替换片段。
这是我的Xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.coboltforge.slidemenu.SlideMenu
android:id="@+id/slideMenu"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</com.coboltforge.slidemenu.SlideMenu>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/buttonMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/menubutton" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonMenu"
android:background="#ff0000" >
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
这是我的MainActivity.java代码的一部分:
@Override
public void onSlideMenuItemClick(int itemId) {
navigateTo(itemId);
}
private void navigateTo(int position) {
switch (position) {
case 0:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame,
StradaBooking.newInstance(),
StradaBooking.TAG).commit();
break;
case 1:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, StradaContact.newInstance(),
StradaContact.TAG).commit();
break;
case 2:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, StradaBooking.newInstance(),
StradaBooking.TAG).commit();
break;
case 3:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, StradaContact.newInstance(),
StradaContact.TAG).commit();
break;
}
}