How to put a title in the fragment?

0

I have the following code, which calls a fragment, in the ScheduleSearch activity:

@Override
public void openFragment(int home, boolean search, boolean changeClickDirection) {
    if (home == 0) {
        PlaceListScheduleFragment fragment = new PlaceListScheduleFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("home_type", 0);
        bundle.putBoolean("search", true);
        bundle.putBoolean("CHANGE_DIRECTION", changeClickDirection);
        fragment.setArguments(bundle);
        getSupportFragmentManager().beginTransaction()
                .add(R.id.containerLinear, fragment)
                .addToBackStack("PlaceListScheduleFragment")
                .commit();
        getSupportFragmentManager().executePendingTransactions();
    } else {
        PlaceListScheduleFragment fragment = new PlaceListScheduleFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("home_type", 1);
        bundle.putBoolean("search", true);
        bundle.putBoolean("CHANGE_DIRECTION", changeClickDirection);
        fragment.setArguments(bundle);
        getSupportFragmentManager().beginTransaction()
                .add(R.id.containerLinear, fragment)
                .addToBackStack("PlaceListScheduleFragment")
                .commit();
        getSupportFragmentManager().executePendingTransactions();
    }
}

It has a ToolBar implemented, but I can not get it to go a title for the open fragment, how do I do that?

EDIT:

XML Activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/containerSearch"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:fitsSystemWindows="true"
    android:gravity="center_horizontal"
    tools:context="com.holandago.schedule.views.ScheduleSearchActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar_Search_ask"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/azul_bynd"
        android:gravity="center"
        app:titleTextColor="@color/button_text_color">

        <TextView
            android:id="@+id/txtToolBarTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="TITULO"
            android:textColor="@color/button_text_color"
            android:textSize="20dp"
            android:visibility="visible"
            android:textStyle="bold" />

    </android.support.v7.widget.Toolbar>
....
<LinearLayout
    android:id="@+id/containerLinear"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:orientation="vertical">

</LinearLayout>

XML Fragment:

<LinearLayout
    android:id="@+id/title_view"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/azul_bynd"
    android:orientation="vertical">

</LinearLayout>


<SearchView
    android:id="@+id/query_schedule"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="18dp"
    android:layout_marginEnd="18dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:padding="1dp"
    android:queryHint="@string/search_hint"
    android:textColor="@android:color/black"
    android:background="@drawable/border_search_address"
    android:elevation="12dp"/>

<ListView
    android:id="@+id/listViewSchedule"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="@null"
    android:dividerHeight="0dp" />

<!--<TextView-->
    <!--android:id="@android:id/empty"-->
    <!--android:layout_width="match_parent"-->
    <!--android:layout_height="match_parent"-->
    <!--android:gravity="center"-->
    <!--android:layout_below="@+id/query_schedule"-->
    <!--android:layout_alignParentStart="true"-->
    <!--android:layout_marginTop="30dp" />-->

    
asked by anonymous 05.05.2017 / 15:12

1 answer

1

You can create a method in your main Activity, like this:

public void setToolbarTitle(String title){
    id_da_toolbar.setText(title);
}

And then, in the Fragment where you want to change the title, you do it this way:

((NomeActivity) getActivity()).setActionBarTitle("Seu_Titulo_Aqui");
    
05.05.2017 / 15:26