我的微调器的 onItemSelected 函数无法识别活动中的变量(声明为最终变量)。对于识别这些相同变量的按钮,我在同一活动中有 onClickListener 函数。
这是一些代码:
public class Currency extends Activity implements OnItemSelectedListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_currency);
final TextView tv2 = (TextView) findViewById(R.id.textView2);
final TextView tv3 = (TextView) findViewById(R.id.textView3);
}
@Override
public void onItemSelected(AdapterView<?> arg0, View v, int position,
long arg3) {
switch (position) {
case 0:
tv2.setText("something");
tv3.setText("something");
break;
case 1:
tv2.setText("something");
tv3.setText("something");
case 2:
tv2.setText("something");
tv3.setText("something");
break;
default:
break;
}
}
错误(每一行旁边):'tv2 无法解析'