从 2 个微调器获取值并显示列表视图?

Get values from 2 spinners and display listview?

场景是——用户从下拉列表中选择学期(sem1、sem2...等)值,并从另一个列表视图中选择其分支(cs、it...),并基于列表视图包含的两个选定值指定学期和分支的科目被填充,并且基于该科目我想显示该科目的教学大纲..

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.syllabus);
        String[] semarray = new String[] { "Sem 1", "Sem 2", "Sem 3" };
        String[] brancharray = new String[] { "CS", "EC", "EE" };
        semester = (Spinner) findViewById(R.id.sems);
        branch = (Spinner) findViewById(R.id.branch);
        semarrayAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, semarray);
        semester.setAdapter(semarrayAdapter);
        brancharrayAdapter = new ArrayAdapter<String>(
                this, android.R.layout.simple_spinner_item, brancharray);
        branch.setAdapter(brancharrayAdapter);


        semester.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {
                item1 = semester.getSelectedItem().toString();
            }

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

            }
        });

        branch.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int position, long id) {
                item2 = branch.getSelectedItem().toString();

            }

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

            }
        });

        if(item1 == "Sem 1" && item2 == "CS"){
            Toast.makeText(this, "hi me hu",Toast.LENGTH_SHORT).show();
        };


    }

如何实现???请帮忙

我是 android

的新手

试试这个:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.syllabus);

    String[] semarray = new String[] { "Sem 1", "Sem 2", "Sem 3" };
    String[] brancharray = new String[] { "CS", "EC", "EE" };

    semester = (Spinner) findViewById(R.id.sems);
    branch = (Spinner) findViewById(R.id.branch);        
    listView = (ListView) findViewById(R.id.listview);

    semarrayAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, semarray);

    semester.setAdapter(semarrayAdapter);

    brancharrayAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, brancharray);

    branch.setAdapter(brancharrayAdapter);


    semester.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                                   int position, long id) {
            item1 = semester.getSelectedItem().toString();

            if(item1 != null && item2 != null){

                String[] listArray = new String[]{item1 + " " + item2};

                listViewAdapter = new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_1, listArray);

                listView.setAdapter(listViewAdapter);

            }

        }

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

        }

    });

    branch.setOnItemSelectedListener(new OnItemSelectedListener() {

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

            item2 = branch.getSelectedItem().toString();

            if(item1 != null && item2 != null){

                String[] listArray = new String[]{item1 + " " + item2};

                listViewAdapter = new ArrayAdapter<String>(this,
                        android.R.layout.simple_list_item_1, listArray);

                listView.setAdapter(listViewAdapter);

            }

        }

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

        }

    });

    if(item1 == "Sem 1" && item2 == "CS"){
        Toast.makeText(this, "hi me hu",Toast.LENGTH_SHORT).show();
    };


}