Get Selected position from Spinner inside ListView


Get Selected position from Spinner inside ListView



I have a ListView of Spinners. I'm trying to get the selected values position out of it. Some of the Spinners have the first item selection automatically selected if there is only 1 item in the list. I have get spinner selected item position of particular row spinner item.


if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.product_attribute_value, parent, false);
holder.lv = (LinearLayout) convertView.findViewById(R.id.lv);
holder.Attributename = (TextView) convertView.findViewById(R.id.attr_name);
holder.Attributevalue = (Spinner) convertView.findViewById(R.id.attr_value);
customSpinnerAdapter = new CustomSpinnerAdapter(context, itemAttriModelArrayList.get(position).getItemAttriDetailArrayList());
holder.Attributevalue.setAdapter(customSpinnerAdapter);
holder.Attributevalue.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position1, long id) {

// Spinner AttrValue = ((Spinner) view.getParent()).findViewById(R.id.attr_value);
Spinner AttrValue = ((LinearLayout) view.getParent()).findViewById(R.id.attr_value);
for (int i = 0; i < itemAttriModelArrayList.size(); i++) {
itemAttriModelArrayList.get(i).setSetposition(holder.Attributevalue.getSelectedItemPosition());
// itemAttriModelArrayList.get(i).setSetposition(0);
}
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
convertView.setTag(holder);
convertView.setTag(R.id.attr_value, holder.Attributevalue);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.Attributename.setText(itemAttriModelArrayList.get(position).getAttribute_name());





For spinner first item is always by default selected. And can you describe more on your purpose
– Brijesh Joshi
Jul 2 at 9:53






i have get selected spinner position of particuler row .and sotre that postion in .if i selet first row spinner first position another spinner not select so it has 0 position .but variable store selected 1 position in every row
– bhoomika patel
Jul 2 at 10:21





Again Spinner always have first value selected by default.
– Brijesh Joshi
Jul 2 at 10:22





that not .but i fi selcte second value of first row and that position is 1. and other spinner has first value that have 0position like...but every row set i selcetd spinner first value position if it 2,1,0 any other
– bhoomika patel
Jul 2 at 10:50





Why are you using for (int i = 0; i < itemAttriModelArrayList.size(); i++) inside your onItemSelected method?
– Brijesh Joshi
Jul 2 at 12:22


for (int i = 0; i < itemAttriModelArrayList.size(); i++)


onItemSelected









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Rothschild family

Cinema of Italy