I have a fragment that contains an EditText where the user will enter his name.
In another fragment is the TextView that will get the name you typed in fragment .
Fragment Edit (where the user will type the name):
public class Editar extends Fragment implements View.OnClickListener{
private EditText editar; private Button okBotao;
View rootview;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.fragment_editar, container, false);
editar = (EditText) rootview.findViewById(R.id.editar);
okBotao = (Button) getActivity().findViewById(R.id.ok);
okBotao.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InicioActivity menu = new InicioActivity();
Bundle args = new Bundle();
args.putString("editar", String.valueOf(editar));
menu.setArguments(args);
}
});
return rootview;
}
}
Fragment Home (where the name will be displayed):
public class Inicio extends Fragment {
TextView text;
View rootview;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.fragment_main, container, false);
TextView text = (TextView)getView().findViewById(R.id.campoNome);
String editar = getArguments().getString("editar");
text.setText(editar);
return rootview;
}
}
In my application I use Navigation Drawer .