[英]setSelection() in a few spinner work incorrect
I have three spinner
with same custom SimpleCurosAdapter
我有三个带有相同自定义
SimpleCurosAdapter
spinner
spinnerX = (Spinner)findViewById(R.id.spinnerX);
spinnerY = (Spinner)findViewById(R.id.spinnerY);
spinnerZ = (Spinner)findViewById(R.id.spinnerZ);
spinnerX.setAdapter(new SpinnerAd(this, R.layout.my_item, c, from, to));
spinnerY.setAdapter(new SpinnerAd(this, R.layout.my_item, c, from, to));
spinnerZ.setAdapter(new SpinnerAd(this, R.layout.my_item, c, from, to));
And when i call (for example): 当我打电话时(例如):
spinnerX.setSelection(1);
spinnerY.setSelection(7);
spinnerZ.setSelection(3);
ALL three spinners setSelection
like last one... at position 3
. 所有三个微调器
setSelection
就像最后一个...在位置3
。 Why? 为什么?
All spinners has same data (one cursor)
所有微调器具有相同的数据(一个光标)
Do all three objects point to the same instance ? 所有三个对象都指向同一个实例吗? (the same resource as loaded from the XML)
(与从XML加载的资源相同)
Problem solved, but i do not understand why does it matter, becouse 问题解决了,但是我不明白为什么这么重要,因为
c == dbRead.query(CalcDBHelper.TABLE_VARIABLES, null, null, null, null, null, null);
Solution, set adapter like this: 解决方案,如下设置适配器:
spinnerX.setAdapter(new SpinnerAd(this, R.layout.formula_variable_item, ActMain.dbRead.query(CalcDBHelper.TABLE_VARIABLES, null, null, null, null, null, null), from, to));
spinnerY.setAdapter(new SpinnerAd(this, R.layout.formula_variable_item, ActMain.dbRead.query(CalcDBHelper.TABLE_VARIABLES, null, null, null, null, null, null), from, to));
spinnerZ.setAdapter(new SpinnerAd(this, R.layout.formula_variable_item, ActMain.dbRead.query(CalcDBHelper.TABLE_VARIABLES, null, null, null, null, null, null), from, to));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.