Passing data with LinearLayout onClick

0

In the software I'm developing when I click on an item in my RecyclerView, I would like it to call another Activity showing the item's photo, price, description and would have it choose the quantity. However, I have already tried some methods, and when I click, it even routes to the receiving Activity, but if the client presses the back key and then selects another item, the information does not update, the first selected item continues to appear. p>

Can anyone help me with this?

NOTE: I am capturing the click using my LinearLayout

OBS2: I'm using Firebase

The ADAPTER

public void onBindViewHolder(final ImageViewHolder holder, final int position) {
        final Upload uploadCurrent = mUploads.get(position);

    holder.textViewId.setText("ID: " + uploadCurrent.getmKey());
    holder.textViewName.setText("Nome: " + uploadCurrent.getName());
    holder.textViewDescricao.setText("Acompanhamento: " + uploadCurrent.getmDescricao());
    holder.textViewPreco.setText("Valor Unitário: R$ " + uploadCurrent.getmPreco());
    holder.linearLayoutProdutosCardapio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mDatabaseRef = FirebaseDatabase.getInstance().getReference("pedidos");

            Upload task = new Upload(uploadCurrent.getmKey(), uploadCurrent.getName(), uploadCurrent.getmDescricao(), uploadCurrent.getmPreco(), uploadCurrent.getImageUrl());

            String uploadId = task.getmKey();


             mDatabaseRef.child(uploadId).setValue(task);



            Intent intent = new Intent(mContext, PedidoActivity.class);
            mContext.startActivity(intent);
        }
    });

THE ACTIVITY OF CARDAPIO WHERE THE CUSTOMER WILL SELECT THE PRODUCT

 mRecyclerView = findViewById(R.id.recycler_view);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mProgressCircle = findViewById(R.id.progress_circle);

    mUploads = new ArrayList<>();

    mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");

    mDatabaseRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                Upload upload = postSnapshot.getValue(Upload.class);
                mUploads.add(upload);
            }

            mAdapter = new ImagemAdapter(ImagemActivity.this, mUploads);

            mRecyclerView.setAdapter(mAdapter);
            mProgressCircle.setVisibility(View.INVISIBLE);


        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Toast.makeText(ImagemActivity.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
            mProgressCircle.setVisibility(View.INVISIBLE);
        }
    });
}

ORDER ADAPTER

public void onBindViewHolder(final PedViewHolder holder, final int position) {
        final Upload upPedidos = mUploadsPedidos.get(position);
        mDataBasePedidos = FirebaseDatabase.getInstance().getReference("pedidos");

    holder.text_preco_item_pedido.setText("Valor Unitário:  R$ " + upPedidos.getmPreco());
    holder.text_descricao_item_pedido.setText(upPedidos.getmDescricao());

    DisplayMetrics displayMetrics = mContextPedido.getResources().getDisplayMetrics();

    final int height = (displayMetrics.heightPixels / 4);
    final int width = (displayMetrics.widthPixels / 2);

    Picasso.with(mContextPedido)
            .load(upPedidos.getImageUrl())
            .resize(width, height)
            .centerCrop()
            .into(holder.foto_pedido_carregado);

}

@Override
public int getItemCount() {
    return mUploadsPedidos.size();
}

public class PedViewHolder extends RecyclerView.ViewHolder {
    private LinearLayout linearLayoutPedidos;
    private ImageView foto_pedido_carregado;
    private TextView text_preco_item_pedido, text_descricao_item_pedido;

    public PedViewHolder(View itemView) {
        super(itemView);
        linearLayoutPedidos = itemView.findViewById(R.id.linearLayoutPedidos);
        foto_pedido_carregado = itemView.findViewById(R.id.foto_pedido_carregado);
        text_preco_item_pedido = itemView.findViewById(R.id.text_preco_item_pedido);
        text_descricao_item_pedido = itemView.findViewById(R.id.text_descricao_item_pedido);
    }
}
}

THE ACTIVITY OF THE ORDER

mRecyclerViewPedidos = findViewById(R.id.recycler_view_pedido);
        mRecyclerViewPedidos.setHasFixedSize(true);
        mRecyclerViewPedidos.setLayoutManager(new LinearLayoutManager(this));


    mProgressBarCirclePedido = findViewById(R.id.progress_circle_pedido);
    mUploadsPedidos = new ArrayList<>();

    mDataBasePedidos = FirebaseDatabase.getInstance().getReference("pedidos");


    mDataBasePedidos.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                Upload up = postSnapshot.getValue(Upload.class);
                mUploadsPedidos.add(up);
            }
            mAdapterPedido = new PedidoAdapter(PedidoActivity.this, mUploadsPedidos);

            mRecyclerViewPedidos.setAdapter(mAdapterPedido);
            mProgressBarCirclePedido.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Toast.makeText(PedidoActivity.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
            mProgressBarCirclePedido.setVisibility(View.INVISIBLE);
        }
    });

}
}
    
asked by anonymous 27.04.2018 / 17:23

0 answers