I've been working between Fragment
's using FragmentManager
's to keep the view of the navigation drawer in my project.
What I want is to get a String from Fragment
A and show it on a TextView
on the Fragment
B. As I'm not working with Intent
's, I don't know how to do that. Can anyone please help me?
Here is a piece of my code to explain how i change the views in my project.
Button button = (Button) view.findViewById(R.id.btn_next);
button.setOnClickListener(new View.OnClicklistener(){
@Override
public void onClick(View v){
Fragment frag_A = new ViewClassB();
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction()
.replace(R.id.container, frag_A)
.commit();
}
});
I have the Main class that have a xml with the Fragment Views called container, there is where i show the content of the Activity.
Here is an example for that XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ViewClassA"
>
<FrameLayout android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#fff"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome"
android:id="@+id/text1"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:textColor="#52D5EC" />
</LinearLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
That's how I show the content in my project. In the View class B I just do a onCreateView
to inflate the elements and work with them.
Again, what I need is to pass a String from the Fragment A
to the Fragment B
. I'm not using intents.
Can anyone help me, please?