0

我到处寻找类似的解决方案,但一无所获;是否可以使用微调器移动到另一个活动?我试图简单地从 switch case 开始明确的意图,但它不起作用

这是我的代码:

//add new movie spinner and callback
    ArrayList<String> addOptions = new ArrayList<String>();
    addOptions.add("Add manually");
    addOptions.add("Add via web");
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,addOptions);
    addMovieSpinner.setAdapter(spinnerAdapter);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    addMovieSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long i) {

            switch (position) {
            case 0:
                Intent intent = new Intent(Home.this, Edit.class);

                break;
            case 1:
                Intent intent1 = new Intent(Home.this, Edit.class);
                break;

            default:
                break;
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });
4

1 回答 1

0

仅仅创建一个 Intent 不会移动到另一个 Activity。您需要像这样实际启动IntentstartActivity()

switch (position) {
    case 0:
        Intent intent = new Intent(Home.this, Edit.class);
        startActivity(intent);
        break;
    case 1:
        Intent intent1 = new Intent(Home.this, Edit.class);
        startActivity(intent1);
        break;
    default:
        break;
}
于 2013-01-03T10:38:38.480 回答