1
Hello, I am learning and I wanted the suggestion of you, in a simple way at first, how to make this passage of products to another Activity. The application I’m developing it loads a list of products from a Webservice, so in the application there is no registration of products, just reading the products available and when doing this reading is already loaded the products in Firebase, where I also store customers who can be registered in the app. So when someone is going to create a new order, my idea is to have three steps. The first is the choice of the customer who will place the order, then the or products that will be ordered, and on the last screen where appears all the information (customer, product and product information: as total value...). On the screen of choosing the products it already loads the information from Firebase, using Firebaseui (Maybe not the best way, but so far it worked well with the customer and is very fast to load) the function I use to load the Recyclerview of the products is this:
public void setupRecycler(){
adapter = new FirebaseRecyclerAdapter<Produto, ProdutoHolder>(
Produto.class,
R.layout.recyclerview_items,
ProdutoHolder.class,
ref
) {
@Override
protected void populateViewHolder(final ProdutoHolder viewHolder, final Produto model, final int position) {
viewHolder.setId(model.getId().toUpperCase());
viewHolder.setNome(model.getNome());
viewHolder.setDescricao(model.getDescricao());
viewHolder.setTamanho(model.getTamanho());
viewHolder.setQuantidade(model.getQuantidade());
viewHolder.setValor(model.getValor());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (SystemClock.elapsedRealtime() - lastClickTime < 1500){
viewHolder.itemView.setBackgroundColor(Color.RED);
return;
}
lastClickTime = SystemClock.elapsedRealtime();
viewHolder.itemView.setBackgroundColor(Color.GREEN);
String idProduto = model.getId();
String nomeProduto = model.getNome();
String descricaoProduto = model.getDescricao();
String tamanhoProduto = model.getTamanho();
String quantidadeProduto = model.getQuantidade();
String valorProduto = model.getValor();
}
});
}
};
recyclerView.setAdapter(adapter);
}
Photos of the stages: [REQUEST] [CHOOSE CLIENT] [PICK PRODUCT] [FINAL SCREEN (not yet finished)
This Onclick was using it for testing, but it works cool that way too, inside the Adapter itself it can get the product information, but how can I pass all this information to another Activity, and if it’s more than one product? I thought about using JSON, I did some tests, but it didn’t work, I’m very doubtful, as you don’t need to change anything of the product, just pass the product information, so maybe an Array already solves. Well that’s my question, it’s always helped the times I ask a question here, so thank you.
This does not pass a Product Array but rather a String Array.
– ramaral
yes, it is true friend @ramaral, but he asked to clarify the doubt, and this the answer did, because regardless of the type of array that is going through, the transport process is the same, as it can fill a "hashmap" with the product, which will have to be shipped via Bundle the same way it is in the reply.
– Armando Marques Sobrinho
Only with the information given in the reply, if instead of
ArrayList<String>
is usedArrayList<Produto>
, won’t work– ramaral
if he has a Product class to pass as Type to Arraylist<Product> it will work the same way, but I based on the code he posted, hence where he passes the product values he passes a String for each data, ex.:
String idProduto = model.getId();String nomeProduto = model.getNome(); ...
and so on, so I responded as a string array– Armando Marques Sobrinho