I have a fragment containing an EditText in which the user will enter his name.
In another fragment is the TextView that will receive the name entered in the previous 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", editar.getText().toString());
menu.setArguments(args);
}
});
return rootview;
}
}
Home Fragment (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) rootview.findViewById(R.id.campoNome);
Bundle bundle = getArguments();
String editar = bundle.getString("editar");
text.setText(editar);
return rootview;
}
}