Resolvido com:
btnConfirm.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (validarCampos()) {
saveData();
// Capture the article fragment from the activity layout
EmprestimoFragment emprestimoFragment = (EmprestimoFragment) getActivity()
.getSupportFragmentManager().findFragmentById(R.id.ListItensFragment);
if (emprestimoFragment == null) {
getActivity().getSupportFragmentManager().popBackStack();
}
}
}
});
Em segunda-feira, 3 de dezembro de 2012 13h03min23s UTC-2, Bugs_Bunny escreveu:
Olá, vou tentar explicar meu problema...Em um smartphone de tela pequena..no qual mostra somente um Fragment por vez..Eu tenho uma FragmentActivity EmprestimoActivity que carrega o Fragment EmprestimoFragment, mas na action bar eu add um botão que carrega o Fragment EditarEmprestimoFragment como mostrado abaixo:EditarEmprestimoFragment newFragment = new EditarEmprestimoFragment();Bundle args = new Bundle();args.putLong(EmprestimoDAO.TABELA_EMPRESTIMOS, id); newFragment.setArguments(args); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment,// and add the transaction to the back stack so the user can navigate backtransaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); transaction.setTransition(FragmentTransaction.TRANSIT_ FRAGMENT_FADE); // Commit the transactiontransaction.commit();Nessa último Fragment (EditarEmprestimoFragment) eu tenho um botão btnConfirmar que iria salvar os dados no banco de dados e retornar para a tela anterior, mas não posso usar o getActivity().finish() senão a EmprestimoActivity será finalizada.Se eu faço :btnConfirm.setOnClickListener(new View.OnClickListener() { public void onClick(View view) {if (validarCampos()) {saveData();// Capture the article fragment from the activity layoutEmprestimoFragment emprestimoFragment = (EmprestimoFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id. ListItensFragment); if (emprestimoFragment == null) {emprestimoFragment = new EmprestimoFragment();emprestimoFragment.setArguments(getActivity(). getIntent().getExtras()); FragmentTransaction transaction = getActivity().getSupportFragmentManager(). beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_ FRAGMENT_FADE); transaction.add(R.id.fragment_container, emprestimoFragment).commit(); }}}});Eu consigo mostrar uma nova instância da tela de EmprestimoFragment, mas ai se eu apertar o botão voltar, voltarei "para a mesma tela" (pelo o que entendi..estou voltando para a primeira instância desse fragment)...como que eu poderia fazer para evitar esse comportamento?Se eu deixo assim:btnConfirm.setOnClickListener(new View.OnClickListener() { public void onClick(View view) {if (validarCampos()) {saveData();// Capture the article fragment from the activity layoutEmprestimoFragment emprestimoFragment = (EmprestimoFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id. ListItensFragment); if (emprestimoFragment == null) {getActivity().getSupportFragmentManager(). beginTransaction().remove( EditarEmprestimoFragment.this) .commit(); }}}});A tela de EditarEmprestimoFragment some, mas fico com uma tela preta..somente com a action bar e os botões..mas sem o Fragment EmprestimoFragment carregado...Desde já, muito obrigado!






0 comentários:
Postar um comentário