I use the spinner as a list (Multiple Spinners) for different products with their images on the left and prices on the right. The user has the choice to select the quantity (s) of each product.
This work goes on in a class that extends from the BaseAdapter according to my needs. In getView spinner, I set the spinner view.
Now I want:
1) when the user selects an element in Spinner, the price of this element is calculated as the sum, and the TextView text on the right is set to this total price. Now this works fine, but when I look at the list, Spinner changes its value to the old one (i.e. the value at position 0), and not to the new one.
2) . Another thing I want to do is to save all these values that come from different spinners in an array, so at the end all the values of different spinners are further calculated as a sum (at first I calculated the values of one product, for example, the price of this product is $ 50, and the user chose that he wants 20 pieces of this product, therefore totall = 20x50 ).
3) And one more thing I want is to get the number of items selected on one counter. And in the same way, store these numbers of each counter in another array, so that in the end they are all calculated as the total number of all products.
, , . , , , .


reset

public class Base_Adapter extends BaseAdapter
{
ImageView image;
TextView name, price;
Context context ;
ArrayList<ItemDetails> IDetails;
RelativeLayout R_Layout;
Activity activit;
public Base_Adapter(Context context , ArrayList<ItemDetails> li)
{
this.context = context;
IDetails = li;
}
public void setLayout(Activity activity, RelativeLayout layout){
R_Layout = layout;
this.activit = activity;
}
@Override
public int getCount() {
return IDetails.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View CV, ViewGroup parent) {
LayoutInflater infleter = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(CV == null)
{
CV = infleter.inflate(R.layout.base_adapter, null);
}
final ItemDetails item = IDetails.get(position);
int min =1;
int max = Integer.parseInt(item.totall_Available());
ArrayList<String> A_list= new ArrayList<String>();
for(int i=1;i<=max;i++)
{
A_list.add("Number of Items :"+i);
}
image = (ImageView) CV.findViewById(R.id.Item_image);
name = (TextView) CV.findViewById(R.id.item_name);
price = (TextView) CV.findViewById(R.id.item_price);
final Spinner quantity = (Spinner) CV.findViewById(R.id.items);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.spinner_textview, A_list);
quantity.setAdapter(adapter);
name.setText(item.name());
quantity.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1, int i, long arg3)
{
if(i>0){
float cal=Float.parseFloat(item.Fisrtprise());
float cal3=cal*i;
price.setText(""+String.format("%.2f", cal3).replace(".", ","));
String s = Float.toString(cal3);
item.Totalprice=s;
}
else{
price.setText(""+String.format("%.2f", Float.parseFloat(item.Fisrtprise())).replace(".", ","));
}
}
public void onNothingSelected(AdapterView<?> arg0){
}
});
return CV;
}
IDetails Class
@SuppressWarnings("serial")
public class IDetails implements Serializable
{
ContentValues colmnValues;
private int no_of_items;
public float Totalprice;
public IDetails(ContentValues values )
{
colmnValues = values;
}
public String title() {
return getValue(colmnValues.get("title"));
}
public void setNo_of_items(int no_of_items) {
this.no_of_items = no_of_items;
}
public int getNo_of_items() {
return no_of_items;
}
public void setTotalprice(float Totalprice) {
this.Totalprice = Totalprice;
}
public float getTotalprice() {
return Totalprice;
}
public String imageUrl() {
return getValue(colmnValues.get("imageUrl"));
}
public String pprice() {
return getValue(colmnValues.get("Realprice"));
}
public String stock() {
return getValue(colmnValues.get("stock"));
}
private String getValue(Object obj){
if(obj == null){
return "";
}
return (String) obj;
}
}