I'm doing an application with NavigationDrawer
, and to not always create another activity
, I'm using fragments
, where at every click I make replace
in FrameLayout
that I left set as main. How do I access the components that each fragment
has? Ex: TextView
(change its text);
My Fragment class
public class EscolheEspecialidadeFragment extends Fragment{
private TextView tvTeste;
private View rootView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_escolhe_especialidade, container, false);
tvTeste = (TextView)rootView.findViewById(R.id.tvTeste);
return rootView;
}
public void setTextoText(String texto)
{
tvTeste.setText(texto);
}
}
Method responsible for calling fragment
public void clickHojeAmanha(View view)
{
EscolheEspecialidadeFragment fragment = new EscolheEspecialidadeFragment();
FragmentManager fn = getFragmentManager();
fn.beginTransaction().replace(R.id.content_frame, fragment).commit();
fragment.setTextoText("teste");
}
Each time the application attempts to seperate the text, it crashes and closes. Please, where is my error?