【发布时间】:2019-10-21 01:14:57
【问题描述】:
我试图从 Activity 到导航抽屉中的特定片段。我正在尝试片段交易,但它对我不起作用。
这是我的代码:
我的活动(点击活动从导航抽屉转到特定片段):
private void checkCarts() {
checkCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fragment=new EppViewCartV2();
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frams, fragment);
ft.commit();
}
}
});
}
[1]: https://i.stack.imgur.com/uuFMq.png
my error (upon using getFragmentManager)
这是我的基本活动(): - 这是应用栏活动:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemViewProducts.EppItemPreviewPhone">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#f2f2f2"
app:elevation="0dp"
android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/view_back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="20dp"
android:src="@drawable/arrow_back"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/qqt"
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/view_cart2"
android:layout_width="26dp"
android:layout_marginRight="10dp"
android:layout_height="26dp"
android:src="@drawable/shopping"/>
</RelativeLayout>
<TextView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="12dp"
android:id="@+id/badge_notification"
android:layout_alignRight="@id/qqt"
android:background="@drawable/item_status"
android:textAlignment="center"
android:text="12"
android:textColor="#fff"
android:padding="3dp"
android:textSize="10sp"
android:textStyle="bold"
></TextView>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_epp_item_preview_phone" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fbutton_add_to_cart"
app:rippleColor="@null"
app:backgroundTint="@null"
app:maxImageSize="30dp"
android:scaleType="center"
android:layout_margin="@dimen/fab_margin"
android:backgroundTint="#b578ff"
app:srcCompat="@drawable/cart_big"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
内容活动:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f2f2f2"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ItemViewProducts.EppItemPreviewPhone"
tools:showIn="@layout/activity_epp_item_preview_phone">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="410dp"
android:layout_marginBottom="8dp"
android:background="@drawable/radius_all"
app:layout_constraintBottom_toTopOf="@+id/relativeLayout4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="240dp">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager2"
android:layout_width="match_parent"
android:background="@drawable/radius_all"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_height="240dp"
android:layout_marginBottom="5dp" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/rightright"
android:layout_centerVertical="true"
android:src="@drawable/leftleft"
android:layout_marginLeft="10dp">
</ImageView>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:id="@+id/leftleft"
android:layout_alignParentRight="true"
android:src="@drawable/rightright"
android:layout_marginRight="10dp">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginTop="70dp"
android:layout_height="match_parent">
<TextView
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp"
android:text="Harman Karton - AURA STUDIO 2"
android:textColor="#000"
android:id="@+id/view_subject"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="245dp"
android:id="@+id/view_on_hand"
android:text="Available(150)"
android:textSize="11dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="238dp"
android:text="P 14,999.00"
android:id="@+id/view_new_price"
android:textColor="#f24800"
android:textSize="21dp"
android:textStyle="bold" />
<TextView
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="270dp"
android:text="P 145,999.00"
android:id="@+id/view_srp"
android:textSize="16dp" />
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="270dp"
android:text=" - 50%"
android:id="@+id/view_discount"
android:textColor="#af0000"
android:textSize="17dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="275dp"
android:layout_marginRight="110dp"
android:layout_alignParentRight="true"
android:text="x"
android:textSize="12dp" />
<ImageView
android:layout_width="20dp"
android:id="@+id/view_btn_less"
android:layout_height="20dp"
android:layout_marginTop="273dp"
android:layout_marginRight="85dp"
android:layout_alignParentRight="true"
android:src="@drawable/left_arrow" />
<TextView
android:layout_width="30dp"
android:layout_height="20dp"
android:layout_marginTop="273dp"
android:layout_marginRight="53dp"
android:layout_alignParentRight="true"
android:text="1"
android:textAlignment="center"
android:id="@+id/view_count"
android:textColor="#000"
android:textSize="14dp" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/view_btn_add"
android:layout_marginTop="273dp"
android:layout_marginRight="30dp"
android:layout_alignParentRight="true"
android:src="@drawable/right_arrow"
android:textSize="17dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="300dp"
android:layout_marginRight="20dp"
android:background="#bababa"
android:src="@drawable/right_arrow"
android:textSize="17dp" />
<TextView
android:layout_width="45dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="310dp"
android:layout_marginRight="150dp"
android:text="Total"
android:textSize="15dp" />
<TextView
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="305dp"
android:layout_marginRight="10dp"
android:text="P 14,999.00"
android:id="@+id/view_total"
android:textColor="#000"
android:textSize="18dp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="420dp"
android:layout_marginBottom="8dp"
android:background="@drawable/radius_all"
app:layout_constraintBottom_toTopOf="@+id/relativeLayout3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/relativeLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="25dp"
android:text="Color Variation"
android:textSize="12dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_centerVertical="true"
android:layout_marginRight="190dp"
android:id="@+id/color5"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_centerVertical="true"
android:layout_marginRight="150dp"
android:id="@+id/color4"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:id="@+id/color3"
android:layout_centerVertical="true"
android:layout_marginRight="110dp"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginRight="70dp"
android:id="@+id/color2"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textSize="17dp" />
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:layout_marginRight="30dp"
android:layout_centerVertical="true"
android:id="@+id/color1"
android:layout_alignParentRight="true"
android:textSize="17dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="478dp"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Product description"
android:textSize="14dp"/>
<TextView
android:layout_width="match_parent"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:background="@drawable/radius_all"
android:textColor="#000"
android:id="@+id/view_product_description"
android:text=" \n \n
- Enter your model number \n \n
- Compatible with all devices with a stereo minijack output \n \n
- Outstanding bass performance \n \n
- Touch volume and mute controls \n \n
- Subwoofer volume control \n \n"
android:textSize="11dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Product specification"
android:textSize="14dp"/>
<TextView
android:layout_width="match_parent"
android:layout_marginTop="3dp"
android:layout_height="wrap_content"
android:background="@drawable/radius_all"
android:textColor="#000"
android:id="@+id/view_product_specification"
android:text=" \n \n
- Enter your model number \n \n
- Compatible with all devices with a stereo minijack output \n \n
- Outstanding bass performance \n \n
- Touch volume and mute controls \n \n
- Subwoofer volume control \n \n"
android:textSize="11dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:text="Other Products"
android:textSize="15dp"
android:textStyle="bold"
android:layout_centerHorizontal="true"/>
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:id="@+id/view_product_other_items"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginTop="3dp"
android:layout_centerHorizontal="true">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
【问题讨论】:
-
错误提示您的布局中没有视图
R.id.frams。您可以发布您在活动中使用的布局吗? -
我有,但它是空白的,因为我只用于捕获数据
-
您发布了
content_epp_drawer.xml文件 - 这与您的活动有什么关系? -
那是我的导航抽屉内容
-
您现在可以看到我的答案,先生,我是如何解决问题的 :)