2
I’m making an application with NavigationDrawer
, and not to create another activity
, I’m using fragments
, where every click replace
in the FrameLayout
that I left set as main. How I access the components that each fragment
does it? Ex: TextView
(alter his text);
My class Fragment
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");
}
Every time the application tries to set the text, it crashes and closes. Please, where is my error?
You want that code on Activity change the text of a Textview existing in the layout of Fragment?
– ramaral
Yes, it would be possible?
– Vitor Herrmann