当我从 Spinner 类中选择选项时,我想打开新表单

我试试这个,但我有语法错误


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tf);
    Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
        this, R.array.tfoptions,android.R.layout.simple_spinner_item);
    adapter2.setDropDownViewResource(
        android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(adapter2);

    spinner2.setOnItemSelectedListener(new MyOnItemSelectedListener());

    public class MyOnItemSelectedListener implements OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
            switch (view.isClickable()) {       <---------------- syntax error
                Spinner spinner2;
            case spinner2.setSelection(0):
                startActivity(new Intent(this,To.class));
                break;
            case spinner2.setSelection(1):
                startActivity(new Intent(this,out.class));
            default:
                break;
            }
        }
        public void onNothingSelected(AdapterView parent) {
            // Do nothing.
        }
    }
}

最佳答案

您试图在第一个 case 块之前声明一个变量。你不可以做这个。将变量声明移至 switch 上方。

关于java - token "{"上的语法错误,此 token 后预期的 SwitchLabels,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5601040/

10-17 00:02