我有一个RecyclerView,它的每一行都有一个微调器和一个按钮。现在我想要,在按钮上单击我应该从单击按钮的特定微调器中选择项目。我如何获取已设置为所选微调器项目的所选项目及其对应的标签。请帮忙。我多年来一直在寻找这个答案。
我想知道如何以及在何处调用getitemselectedListener以及如何获取所选项目。
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
if(list.get(position).item_image != null && !(list.get(position).item_image.equals(""))){
Picasso.with(context).load("http://gmart.store/"+list.get(position).item_image).into(holder.imgview_product);
}
else{
holder.imgview_product.setImageResource(R.drawable.cart);
}
// checking if actual price and selling is null then set price = NA and disable add to cart button
if(list.get(position).item_actual_price.equals("") || list.get(position).item_selling_price.equals("")){
holder.txtview_name.setText(list.get(position).item_name);
holder.txtview_marrate.setText("\u20B9 NA");
holder.txtview_marrate.setPaintFlags(holder.txtview_marrate.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
holder.txtview_gmartrate.setText("\u20B9 NA");
holder.btnadd.setEnabled(false);
}
else{
dropdown = new ArrayList<>();
tag_price = new ArrayList<>();
price = 0;
String unitkey = list.get(position).unit_key;
price = Integer.parseInt(list.get(position).item_price_for_1);
String[] unit_key = unitkey.split(",");
dropdown.add(unit_key[0]+" gm for Rs."+list.get(position).item_price_for_1);
tag_price.add(Integer.parseInt(list.get(position).item_price_for_1));
for(int i=1;i<unit_key.length;i++){
int a = price*Integer.parseInt(unit_key[i]);
int res = a/100;
if(Integer.parseInt(unit_key[i])>=1000){
int converttokgs = Integer.parseInt(unit_key[i])/1000;
dropdown.add(converttokgs+" kg for Rs."+res);
tag_price.add(res);
}
else if(Integer.parseInt(unit_key[i])<1000){
dropdown.add(unit_key[i]+" gm for Rs."+res);
tag_price.add(res);
}
}
holder.spinner_unit.setAdapter(spinnerArrayAdapter);
holder.spinner_unit.setTag(R.id.amount,tag_price);
adapter = new Spinner_customAdapter(context,dropdown,tag_price);
holder.spinner_unit.setAdapter(adapter);
holder.spinner_unit.setSelection(3);
holder.spinner_unit.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
Toast.makeText(context, item, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
holder.txtview_name.setText(list.get(position).item_name);
holder.txtview_marrate.setText("\u20B9 "+list.get(position).item_actual_price+"/"+list.get(position).abbrivation);
holder.txtview_marrate.setPaintFlags(holder.txtview_marrate.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.txtview_gmartrate.setText("\u20B9 "+list.get(position).item_selling_price+"/"+list.get(position).abbrivation);
holder.btnadd.setOnClickListener(new BtnAddListener());
}
}