'How do I add multiple values from a Spinner to a TextView in Android?

I am building a simple grocery ordering App with firebase, where I want two spinners and a button.

  • One Spinner for the item name and item price tag. (For example - 'Chips -5rs-')
  • Second spinner for the quantity. (for Example - '5 packet')
  • A button for taking the values from the spinners and putting it to the TextView below. (One item after the other.)

For Example, after adding several items from the spinners, the textview below should look like this. -

  • Chips -5rs- 5 packet
  • Biscuits -20rs- 20 packet
  • Noodles -15rs- 2 packet

and so on..

How do I actually implement it? and if anyone could help me with actual java codes, I would be very thankful. I've also attached a picture below of how I am trying to Implement it. I am new to Android Development and I have keen interest in it.. any help would be deeply appreciated..

:) Thankyou ..

This is the Screenshot of what I am trying to approach.



Solution 1:[1]

You can do it this way, Firstly grab the values from both the spinners

//From spinner 1
String s1_val = spinner1.getSelectedItemsAsString(); 
//From spinner 2
String s2_val = spinner2.getSelectedItemsAsString(); 

Concat the values and set it to the text view.

//concat and set to textView
textView.setText(s1_val.concat(s2.val()));

Perform this on the onClick of Add Items button.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pritish Deshpande