我在listview中有一个微调器。
适用于列表的适配器
listQuantities = database.getItemQuantities(id);
Log.d("List size", listQuantities.size()); //getting 2 in first row
QuantityArrayAdapter adapter = new QuantityArrayAdapter(context, R.layout.spinner_item_black, listQuantities);
spQuantity.setAdapter(adapter);
spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
listQuantities = database.getItemQuantities(id);
Log.d("size", listQuantities.size()); //getting only one in first row
Quantity selectedQuantity = listQuantities.get(arg2); //index out of bound
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
适用于微调器的适配器
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater
.inflate(R.layout.spinner_quantity, parent, false);
}
Quantity quantity = quantities.get(position);
TextView tvQuantity = (TextView) rowView.findViewById(R.id.textView1);
tvQuantity.setText(quantity.toString());
return rowView;
}
锭床工人已正确填充。但是在选择项目时,它会显示索引超出范围。