Transfer objects between Ragments

Asked

Viewed 166 times

0

Good evening.. I’m a beginner in Java Android and I’m developing an application to be used on Gertec’s credit card machine. However my application will have other forms of payment besides card (cash, check, note term). I’m making the sale part with cash, where on the main screen (Fragment) has a recycleview with payment methods. When the user clicks on the form of payment money I display to him a dialog Fragment with a field where he can inform the amount he is paying. Follow the code of how I’m using

rcvFormaPagamento.addOnItemTouchListener(new RecyclerTouchListener(getContext(), rcvFormaPagamento, new ClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            FormaPagamento formaPagamento = listaFormaPagamento.get(position);
            FormaPagamentoBo formaPagamentoBo = new FormaPagamentoBo(getContext());
            switch (position) {
                case 0:
                    //TODO Finalização da venda em Dinheiro
                    formaPagamentoBo.FinalizarVenda(formaPagamento);
                    break;
                case 1:
                    //TODO Finalização da venda em Cartão de Crédito
                    Toast.makeText(getContext(), formaPagamento.getDescricao(), Toast.LENGTH_SHORT).show();
                    break;
                case 2:
                    //TODO Finalização da venda em Cartão de Débito
                    Toast.makeText(getContext(), formaPagamento.getDescricao(), Toast.LENGTH_SHORT).show();
                    break;
                case 3:
                    //TODO Finalização da venda em Nota a Prazo
                    Toast.makeText(getContext(), formaPagamento.getDescricao(), Toast.LENGTH_SHORT).show();
                    break;
                case 4:
                    //TODO Finalização da venda em Boleto
                    Toast.makeText(getContext(), formaPagamento.getDescricao(), Toast.LENGTH_SHORT).show();
                    break;
                default:
                    Toast.makeText(getContext(), "Funcionalidade não implementada", Toast.LENGTH_SHORT).show();
                    break;
            }
        }

        @Override
        public void onLongClick(View view, int position) {

        }
    }));

As a matter of organization, I created a class to handle each form of payment. Example of the Formapayment class calling the Money class

 @Override
public void FinalizarVenda(FormaPagamento entidade) {
    switch (entidade.getCodigoFormaPagamento()) {
        case 1:
            Dinheiro dinheiro = new Dinheiro();
            dinheiro.setDescricao(entidade.getDescricao());
            dinheiro.setCodigoFormaPagamento(entidade.getCodigoFormaPagamento());
            dinheiro.setTotal(entidade.getTotalFormaPagamento());
            dinheiro.setPago(entidade.getTotalFormaPagamento());
            dinheiro.setTroco(0);
            DinheiroBo dinheiroBo = new DinheiroBo(context);
            dinheiroBo.Pagar(dinheiro);
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
    }
}

Class money in turn, calling dialogfragment

    @Override
public void Pagar(Dinheiro entidade) {
    FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager();
    FragmentFormaPagamentoDinheiro fragmentFormaPagamentoDinheiro = FragmentFormaPagamentoDinheiro.newInstance(entidade);
    fragmentFormaPagamentoDinheiro.show(fragmentManager, "frag_forma_pagamento_dinheiro");
}

In this dialogframent I have a button to confirm that you should continue the payment process.

So far so good, the problem is when it confirms the value and I need to give continuity in the completion of the sale, I do not know how to take this data that was informed and join with the other data of the sale to be able to give continuity. Any help is welcome Thank you

  • Hello @Willian welcome to Stackoverflow, please add some code snippets so we can understand how you are running this process and find a solution, I suggest you read [mcve]

  • 1

    Opa @Lucasduete, edited the question. Thanks

  • See if this content helps you: https://www.androidpro.com.br/blog/development-android/fragments/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.