I want to create an activity that can switch between two fragments with different background. I can switch betwee both fragment with two buttons.
I have my Activity setup like this when I start my activity :
cardEditor
My fragment is in green, the four button are not in the fragment. By default, my fragment set is addCardEditor. When I click the button "ajouter", the app is supposed to put the addCardEditor fragment. And when I click the button "Voir", I am supposed to see my second fragment wich is called viewCardEditor.
BUT when I start my activity, then when I push the "Voir" button, I have this
The background is still green without any button, but I have set the background to gray for my viewCardEditor fragment !
And when I push the "ajouter" button to have my addCardEditor displayed, it doesn't change anything ! I still have the exact same thing. If I push any button, it alwayws stay in this state ! Both of my fragment are overlap by this green background.
Then when I try to rotate the smartphone, I have an error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jean.cartememoire/com.example.jean.cartememoire.CardEditor}: android.view.InflateException: Binary XML file line #65: Binary XML file line #65: Error inflating class fragment
I made research on stackoverflow and other website but I didn't found any solution to my problem. Thank you for helping me
My cardEditor activity and his xml :
package com.example.jean.cartememoire;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import layout.AddCardEditor;
import layout.ViewCardEditor;
public class CardEditor extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_editor);
}
public void switchFragment(View v)
{
Fragment fg;
FragmentManager fm;
FragmentTransaction ft;
if(v == findViewById(R.id.buttonAddCard))
{
fg = new AddCardEditor();
fm = getSupportFragmentManager();
ft = fm.beginTransaction();
ft.replace(R.id.fragment_card_editor, fg);
ft.commit();
}
if(v == findViewById(R.id.buttonViewCard))
{
fg = new ViewCardEditor();
fm = getSupportFragmentManager();
ft = fm.beginTransaction();
ft.replace(R.id.fragment_card_editor, fg);
ft.commit();
}
}
}
Xml for cardEditor :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_card_editor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.jean.cartememoire.CardEditor"
android:orientation="vertical"
android:weightSum="1"
android:background="#android:color/black">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="#string/modifier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonModCard"
android:padding="0dp"
android:paddingBottom="0dp"
android:layout_weight="1"
android:onClick="switchFragment"
tools:ignore="ButtonStyle,RtlSymmetry" />
<Button
android:text="#string/supprimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonDeleteCard"
android:padding="0dp"
android:paddingBottom="0dp"
android:layout_weight="1"
android:onClick="switchFragment"
tools:ignore="ButtonStyle,RtlSymmetry" />
<Button
android:text="#string/voir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonViewCard"
android:onClick="switchFragment"
tools:ignore="ButtonStyle" />
<Button
android:text="#string/ajouter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonAddCard"
android:padding="0dp"
android:paddingBottom="0dp"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:onClick="switchFragment"
tools:ignore="ButtonStyle,RtlSymmetry" />
</LinearLayout>
<fragment
android:id="#+id/fragment_card_editor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:name="layout.AddCardEditor"
tools:layout="#layout/fragment_view_card_editor" />
</LinearLayout>
Then there is my first Fragment :
package layout;
public class AddCardEditor extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
if (container != null) {
container.removeAllViews();
}
return inflater.inflate(R.layout.fragment_add_card_editor, container, false);
}
}
with his xml :
<android.support.constraint.ConstraintLayout 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="layout.AddCardEditor"
android:background="#android:color/holo_green_light">
<TextView
android:text="#string/ajouter_une_carte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:elevation="0dp"
tools:ignore="UnusedAttribute"
tools:layout_constraintTop_creator="1"
android:layout_marginStart="129dp"
android:layout_marginTop="16dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="129dp" />
<TextView
android:text="#string/difficult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView11"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="80dp"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView
android:text="#string/th_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
tools:ignore="UnknownId"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="#+id/textView9"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="32dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintRight_toRightOf="#+id/textView9" />
<TextView
android:text="#string/question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView9"
tools:ignore="MissingConstraints"
tools:layout_constraintTop_creator="1"
android:layout_marginTop="104dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:text="#string/r_ponse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView10"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_constraintTop_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:layout_width="279dp"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editTheme"
tools:ignore="MissingConstraints"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/textView5"
android:layout_marginStart="8dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toRightOf="#+id/textView9"
android:layout_marginLeft="8dp" />
<EditText
android:layout_width="281dp"
android:layout_height="126dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editQuestion"
android:layout_marginStart="8dp"
app:layout_constraintTop_toTopOf="#+id/textView9"
app:layout_constraintLeft_toRightOf="#+id/textView8"
android:layout_marginLeft="8dp" />
<EditText
android:layout_width="281dp"
android:layout_height="136dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/editReponse"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#+id/editQuestion"
app:layout_constraintLeft_toLeftOf="#+id/editQuestion" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ratingBar"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/editReponse"
app:layout_constraintLeft_toLeftOf="#+id/editReponse" />
</android.support.constraint.ConstraintLayout>
Then the second fragment :
package layout;
public class ViewCardEditor extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
if (container != null) {
container.removeAllViews();
}
return inflater.inflate(R.layout.fragment_view_card_editor, container, false);
}
}
with his 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="layout.ViewCardEditor"
android:background="#android:color/darker_gray" />
PS : I put Hi in my title because I could not add Hi in the start of my post, so weird... and sorry for bad english
I want to create an activity that can switch between two fragments with different background.
If by "switch" you mean adding/removing fragments, then none of these fragments can be part of your XML layout - in general you can consider XML based structure as (kind of) read-only. So in your project you need to replace your <Fragment> by view group container, i.e. <FrameLayout>, then instantiate your Fragments from code at runtime and add to said container. And since these fragments were not part of the XML, you will be able to remove them (or replace) later w/o any problems.
Related
The program did not report any errors, but when I clicked the button to jump to the fragment, the program crashed directly and still did not report any errors.
This is MainActicity code:
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.ic_launcher_background);
}
public void selectFragment(View view) {
Fragment fragment;
switch (view.getId()){
case R.id.button:
fragment = new testFragment();
break;
case R.id.button3:
fragment = new secTestFragment();
default:
throw new IllegalStateException("Unexpected value: " + view.getId());
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.fragment2, fragment).commit();
}
}
This is my main activity layout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="267dp"
android:layout_marginBottom="160dp"
android:contentDescription="TODO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
tools:srcCompat="#tools:sample/avatars" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="42dp"
android:layout_marginEnd="137dp"
android:layout_marginBottom="220dp"
android:onClick="selectFragment"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toTopOf="#+id/fragment2"
app:layout_constraintVertical_bias="0.663" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="186dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="137dp"
android:text="textButton"
android:onClick="selectFragment"
app:layout_constraintBottom_toBottomOf="#+id/fragment2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/button" />
<fragment
android:id="#+id/fragment2"
android:name="com.example.fragmenttest.testFragment"
android:layout_width="408dp"
android:layout_height="411dp"
android:layout_marginTop="240dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is the first fragment page layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".testFragment">
<ImageView
android:id="#+id/testImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:src="#tools:sample/avatars"
android:src="#drawable/burwood"/>
</FrameLayout>
This is the second fragment page layout.
<?xml version="1.0" encoding="utf-8"?>
<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=".secTestFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="#+id/fragmentTextView"
android:layout_width="match_parent"
android:layout_height="106dp"
android:gravity="center"
android:text="#string/hello_blank_fragment"
android:textSize="36sp"
android:textStyle="bold" />
</FrameLayout>
I hope can get some suggestion. Thank you!
You will want to debug your application and you can set a breakpoint before it crashes. Then step over the crash and you should se the crash in the debug console or in the logcat output. If for some reason they are not there, you can run adb logcat in the terminal and watch the output as you run your application and it will log the crash there.
Logcat tool in Android Studio
You can find more information on command-line logcat https://developer.android.com/studio/command-line/logcat
Basically, this is the code I have right now...
ViewCard activity
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;
import com.team46.stubank.R;
public class DisplayCards extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_cards);
}
public void viewCard(View view){
Intent intent = new Intent(this, ViewCard.class);
startActivity(intent);
}
#SuppressLint("SetTextI18n")
public void toggleDetails(View view){
Switch simpleSwitch = findViewById(R.id.switch1);
TextView tv = findViewById(R.id.textView4);
TextView tv1 = findViewById(R.id.textView);
TextView tv2 = findViewById(R.id.textView5);
TextView tv3 = findViewById(R.id.textView6);
if (simpleSwitch.isChecked()){
tv.setText("card.getCardNumber");
tv1.setText("user.getName");
tv2.setText("card.getSortCode");
tv3.setText("card.getAccountNumber");
//needs to call getter methods from card and user classes
}
else{
tv.setText("0000-0000-0000-0000");
tv1.setText("Joe Bloggs");
tv2.setText("11-11-11");
tv3.setText("3411-4885-6324-7195");
}
}
}
xml page:
?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".card_activities.DisplayCards">
<androidx.cardview.widget.CardView
android:layout_width="362dp"
android:layout_height="172dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="100dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:onClick="viewCard"
app:cardBackgroundColor="#6C4095"
app:cardCornerRadius="20dp"
app:cardElevation="15dp"
app:cardMaxElevation="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="viewCard">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:fontFamily="#font/roboto_medium"
android:text="#string/card_number_default"
android:textColor="#FFFFFF"
android:textSize="22sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:fontFamily="#font/roboto_medium"
android:text="#string/name_default"
android:textColor="#FFFFFF"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="59dp"
android:layout_height="47dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/mastercard_small" />
<Switch
android:id="#+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:fontFamily="#font/roboto_medium"
android:onClick="toggleDetails"
android:text="#string/toggle_card_details"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="14dp"
android:fontFamily="#font/roboto_medium"
android:text="#string/sortcode_default"
android:textColor="#FFFFFF"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:fontFamily="#font/roboto_medium"
android:text="#string/account_number_default"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="79dp"
app:cardBackgroundColor="#6d0095"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/cards_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:fontFamily="#font/roboto_medium"
android:text="#string/cards_menu"
android:textColor="#FFFFFF"
android:textSize="36sp" />
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
The code here is basically a screen with a card, made up of various components, in order to resemble a credit/debit card containing the user's information. Similar to this. What I want to do, is to allow the user to add multiple "cards" by clicking onto a button. I'm not sure how to go about this exactly so any help would be much appreciated.
You have 3 (I think) basic ways to do it - they all involve pulling your single card layout into its own XML file:
Use the layout as a list item in a ListView, or (preferably) a ViewHolder in a RecyclerView. Each item gets a card layout, and you set the details on the things - the actual data for each card is stored in a list and you just display the appropriate stuff
Create a custom View (compound controls really, just bundling some Views together) which inherits from something like FrameLayout, and inflate your XML layout into that. That way each card is its own object and you can use them as widgets in any other layout
Make each card a Fragment which is a little simpler than creating a View (since it handles all the layout inflation stuff for you) but is probably a bit harder to work with in terms of adding them to a layout.
Really it depends what you want - a simple list with a RecyclerView might be best, if you want flexibility you could make the custom View and stick one of those in a basic layout and use that as your ViewHolder layout
Above is the path I follow until I reach the BeginnerFragment.
Above is the hierarchy of activity / fragments
Current Situation
In my application I have a Bottom Navigation, and in each fragment of the navigation, I have two tabs.
The Problem
My problem is that when I'm at BeginnerFragment and I press the cell back button, it returns to the StatusFragment.
I expected it to return to EducationHomeFragment, as I added it to BackStack, according to the codes below.
EducationFragment
public class EducationFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_education, container, false);
// Instanciando o Fragmento de página inicial da Educação
EducationHomeFragment educationHomeFragment = new EducationHomeFragment();
getActivity().getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, educationHomeFragment).addToBackStack(null).commit();
return root;
}
}
fragment_education
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/fragment_container"
tools:context=".education.EducationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
EducationHomeFragment
public class EducationHomeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_education_home, container, false);
CardView beginnerFreelance = root.findViewById(R.id.cardview_beginner_skills);
beginnerFreelance.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BeginnerFragment fragment = new BeginnerFragment();
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container , fragment)
.addToBackStack(null)
.commit();
}
});
return root;
}
}
fragment_education_home
<androidx.constraintlayout.widget.ConstraintLayout 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:id="#+id/fragment_education_home_container"
tools:context=".education.EducationHomeFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEE"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/text_academic_education"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/academic_education"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_advanced_skills" />
<TextView
android:id="#+id/title_courses_available"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/general_courses"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_qualifications" />
<androidx.cardview.widget.CardView
android:id="#+id/cardview_doctoral_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_master_courses">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/doctoral_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_master_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_specialization_courses">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/master_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_specialization_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_higher_courses">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_doctoral_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/specialization_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_higher_courses"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_academic_education">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_master_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/higher_level_courses"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_advanced_skills"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_intermediate_skills">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_specialization_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/advanced"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_study_status"
android:layout_width="match_parent"
android:layout_height="85dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/default_cardview_mgtop"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image_study_status"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="10dp"
android:tint="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/outline_menu_book_24" />
<TextView
android:id="#+id/text_study_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/not_studying"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image_study_status" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_qualifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/default_cardview_mgtop"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_study_status">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp">
<TextView
android:id="#+id/title_obtained_qualifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qualifications_obtained"
android:textColor="#color/colorPrimaryDark"
app:fontFamily="#font/exo_2_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/obtained_qualification_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/no_course_completed"
app:fontFamily="#font/exo_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_obtained_qualifications" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_beginner_skills"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/title_courses_available">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_basic_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/beginner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardview_intermediate_skills"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="#dimen/default_cardview_mgsides"
android:layout_marginTop="#dimen/cardview_list_margin"
android:layout_marginRight="#dimen/default_cardview_mgsides"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardview_beginner_skills">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text_higher_courses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intermediate"
app:fontFamily="#font/exo_2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Why isn't FragmentEducationHome being added to the stack? I want to return to FragmentEducationHome when I click on the BeginnerFragment back button.
This is not a direct answer to the question.
But Google suggests to use Jetpack Navigation approach.
Which will be single Activity and multiple fragments.
Google Code Labs Link
This avoids lot of bipolarate code , were we had to handle backstack, keeping fragment count etc...
At first anyone will feel bit difficult to start with, but in a while , you can grasp and move on to new approach which is suggestible.
Nav_graph avoids programmers responsibility to add/ remove fragments
Allows passing data (raw data or data classes with Parcelable) from one fragment to another
Moving from one child nav graph to another
And much more...
I would suggest you do checkout this once starting with a new trial/project
EDIT
Even though one activity is suggested, we may have more than one Activity and its corresponding child fragment graphs if required. This purely depends on the requirement. In my last project we started with single activity concept. But as the app complexity increased, it was decided to move for two activity and its corresponding child frags.
With respect to Clean Code Architecture this is easily adaptable as well...
Good luck!
Please refer to this question:
Override onBackPressed() into your activity and call this in order to remove current fragment from backstack, since you add it.
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
getSupportFragmentManager().popBackStackImmediate()
} else {
finish();
}
Make sure R.id.fragment_container lives in the parent activity xml (not the fragment xml) and in EducationHomeFragment use .add instead of .replace to add BeginnerFragment to the back stack
You already replace current container fragment by BeginnerFragment, so you can't back to previous fragment. Try to use add(id, fragment, tag) and addToBackStack(tag). Hope help you.
I am new to Android development. An Fragment problem that a Fragment layout in another Fragment cannot be shown. I used almost one week on solution seeking...
If I inflate "fragment_main2" from MainFragment.java, it failed to run. But if I inflate "fragment_checker.xml", it is fine. Any advise, thanks a lot!
The structure is showing as below:
MainActivity.java (Create and show the MainFragment)
package a3.webchecker;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
public class MainActivity extends AppCompatActivity {
public StringBuilder log = new StringBuilder("Web Checker Log:\n");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main2);
Fragment fragment = new MainFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit();
}
}
MainFragment.java (Inflate fragment_main2.xml)
package a3.webchecker;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public class MainFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main2, container, false);
return view;
}
}
activity_main.xml (Contain a FrameLayout container)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:padding="8dp"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
fragment_main2.xml (contain Fragment tab & layout is using fragmentChecker.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainFragment">
<fragment
android:id="#+id/web_checker_1"
android:name="a3.webchecker.CheckerFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
tools:layout="#layout/fragment_checker" />
<Button
android:id="#+id/view_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Log" />
</LinearLayout>
fragment_checker.xml (Layout)
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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"
app:cardUseCompatPadding="true"
app:contentPadding="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:context=".CheckerFragment">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="URL:"
app:layout_constraintBaseline_toBaselineOf="#+id/url"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status: "
app:layout_constraintBaseline_toBaselineOf="#+id/status"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/status"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/url" />
<Button
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Check"
app:layout_constraintEnd_toStartOf="#+id/go_to"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/status" />
<Button
android:id="#+id/go_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/check"
app:layout_constraintTop_toTopOf="#+id/check" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
In "fragment_main2.xml", you no correct to set your activity in tools:context
Repair to become this
tools:context=".MainActivity"
And because you implement fragment transaction, you have to define layout fragment in your activity.
<LinearLayout 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"
android:padding="8dp"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="[your fragment location]"
android:id="#+id/fragment_container" />
</LinearLayout>
I am trying to make a basic Countdown app.
Below is my main Activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="com.example.dot.timer.MainActivity">
<Chronometer
android:id="#+id/chronometer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="108dp"
android:textSize="70sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="#+id/fragment"
android:name="com.example.dot.timer.SetTimer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/chronometer" />
</android.support.constraint.ConstraintLayout>
I have created two fragments
1)SetTimer.java\fragment_set_timer.xml With a EditText and Button
2)TimerButtons.java\fragment_timer_buttons.xml Three Buttons
SetTimer Activity is below
public class SetTimer extends Fragment{
View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view=inflater.inflate(R.layout.fragment_set_timer, container, false);
Button button=(Button)view.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
FragmentManager fm=getFragmentManager();
FragmentTransaction ft =fm.beginTransaction();
Fragment fragment=new TimerButtons();
ft.replace(R.id.fragment,fragment);
ft.addToBackStack(null);
ft.commit();
}
});
return view;
}}
SetTimer xml is below
<FrameLayout 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="com.example.dot.timer.SetTimer">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
app:layout_constraintBaseline_toBaselineOf="#+id/button"
app:layout_constraintEnd_toStartOf="#+id/button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/editText2"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</FrameLayout>
When i run the project and click on Set Button
this is what happens
and background frame is even Clickable
but shouldn't using .replace() destroy previous fragment
Why is it happening and how can i correct it?