In my MainActivity
layout, I have a TabLayout
with ViewHolder
and I'm opening Fragment
from the adapter in my MainActivity
. But the Fragment
not showing properly,
I also refer this link but it's different, I m not able to solve my problem.
Here's main_activity_layout.xml
:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="58dp"
android:layout_marginTop="58dp" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/custom_tab_layout_height"
android:layout_alignParentBottom="true"
app:tabBackground="@drawable/tab_color_selector"
app:tabGravity="fill"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed" />
</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/availibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Availability"
android:textColor="@color/tab_background_selected"
android:textSize="16sp" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchAvailible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="16dp"
android:theme="@style/Custom.SwitchCompat.WhiteTrack" />
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Home"
android:textColor="@color/tab_background_selected"
android:textSize="16sp"
android:visibility="gone" />
<LinearLayout
android:id="@+id/searchview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@drawable/circle_edit"
android:hint="What are you hungry for?"
android:imeOptions="actionDone"
android:maxLines="1"
android:singleLine="true"
android:textColor="#212121"
android:textColorHint="#aaaaaa"
android:textSize="16sp" />
<Button
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/search" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/main_contenier"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/appBarLayout"
android:orientation="vertical">
</FrameLayout>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="60dp"
android:layout_marginRight="10dp"
app:borderWidth="0dp"
app:fabSize="normal"
app:fab_colorNormal="#da3c2f"
app:fab_colorPressed="#dc4b3f"
app:rippleColor="#99d4d4d4"
fab:menu_icon="@drawable/filterwhite" />
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/material_design_android_floating_action_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="50dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
android:visibility="gone"
app:borderWidth="0dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#da3c2f"
fab:menu_colorPressed="#dc4b3f"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/fab_add"
fab:menu_labels_colorNormal="#333"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#f2f1f1"
fab:menu_labels_textSize="15sp"
fab:menu_openDirection="up">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tiffinewhite"
fab:fab_label="Tiffin Service"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/material_design_floating_action_menu_item3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dishes_white"
fab:fab_label="Add Dishes"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
<com.github.fabtransitionactivity.SheetLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:elevation="2dp"
app:ft_color="@color/colorPrimaryDark"
app:ft_container_gravity="center" />
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_dashboard"
app:menu="@menu/activity_dashboard_drawer" />
</android.support.v4.widget.DrawerLayout>
My MainActivity
view before opening the Fragment
.
And after opening the Fragment
it looks like this:
Here's how I make the fragment transaction.
((MyViewHolder) holder).checkout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = ((AppCompatActivity) mContext).getSupportFragmentManager();
PaymentFragment paymentFragment = new PaymentFragment();
manager.beginTransaction().add(R.id.main_contenier,paymentFragment).addToBackStack(null).commit();
}
});
So my question is how can I show my Fragment
? Is there any other way? I can't apply DialogFragment
here. How to show fragment as a new blank Activity
?