Go from an activity to a fragment

1

I am creating an application in which the user starts from a fragment, he is redirected to an activity where he introduces a series of data and I want him to return to the fragment from which he left. But at the time of returning to the fragment of departure the intent gives me error.

If I put:

        Intent intent = new Intent(AddClothingSetActivity.this, MainActivity.class);
        startActivity(intent);

The application loads the startup fragment, but I do not want it to load this.

I've tried with:

    Intent intent = new Intent(AddClothingSetActivity.this, ClothingSetsFragment.class);
    startActivity(intent);

What is the fragment I want to go to, but I get an error. Error: Unable to find explicit activity class. Have you declared this activity in your AndroidManifest.xml? The activity of which the fragment hangs is declared, How to go to the fragment that I want?

Here is the layout code of the AddClothingSetActivity activity:

<TextView
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/textViewWhite"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/textViewClothes"
    android:layout_below="@id/textViewWhite"
    android:text="Prendas"
    android:textSize="30dp"/>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_below="@+id/textViewClothes"
    android:id="@+id/scrollViewClothes">
</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_below="@id/scrollViewClothes"
    android:orientation="horizontal"
    android:id="@+id/linearLayoutAdd">

    <TextView
        android:layout_width="20dp"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:id="@+id/buttonAddClothes"/>
    <TextView
        android:layout_width="20dp"
        android:layout_height="match_parent" />
    <TextView
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:text="Añadir prendas"
        android:textSize="25dp"
        android:paddingTop="12dp"/>

</LinearLayout>

<EditText
    android:id="@+id/editTextClothingSetsName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Name"
    android:inputType="textPersonName"
    android:layout_below="@id/linearLayoutAdd"
    android:paddingTop="20dp"/>
<EditText
    android:id="@+id/editTextClothingSetsDescription"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Descripcion"
    android:inputType="textMultiLine"
    android:layout_below="@id/editTextClothingSetsName"
    android:paddingTop="15dp"/>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frameLayout"
    android:layout_below="@id/editTextClothingSetsDescription">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/FABEditClothingSets"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@android:drawable/ic_menu_save"
        app:backgroundTint="@color/colorAccent"
        app:borderWidth="16dp" />

</FrameLayout>

    
asked by CMorillo 05.04.2018 в 19:41
source

1 answer

2

Unable to open a Fragment using a Intent .

What is done is to make transactions of Fragments within a FrameLayout , if you have specified a FrameLayout , this is where you can load your Fragments:

To add the Fragment called ClothingsSetsFragment simply make a transaction to add the Fragment :

        //Obtiene el Fragment manager
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        //agrega el Fragment en el contenedor, en este caso el FrameLayout con id 'FrameLayout'.
        ft.add(R.id.frameLayout, new ClothingsSetsFragment());
        ft.commit();
    
answered by 05.04.2018 / 23:16
source