根据所选类别填充微调器条目

时间:2014-05-13 15:41:11

标签: android spinner

我试图根据从前一个微调器中选择的类别填充我的spinner2。我有不同的字符串数组将被使用。我在页面上搜索了一些可以帮助我的东西,但这一切都无济于事 这是我的旋转器

           spinner1 = (Spinner) findViewById(R.id.spinner1);
            spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapter, View v,
                int position, long id) {
            // On selecting a spinner item
             frmCatg = adapter.getItemAtPosition(position).toString();


        }

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

        }
    });
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapter, View v,
                int position, long id) {
            // On selecting a spinner item
            frmApplnce = adapter.getItemAtPosition(position).toString();

        }

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

        }
    });

    spinner3 = (Spinner) findViewById(R.id.spinner3);

    spinner3.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapter, View v,
                int position, long id) {
            // On selecting a spinner item
            frmWatts = adapter.getItemAtPosition(position).toString();
         inWatts = Integer.parseInt(frmWatts);

        }

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

        }
    });

1 个答案:

答案 0 :(得分:0)

如果在第一个微调器中选择一个项目,则必须填充第二个微调器的列表。

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, <your string-array resource>;
spinner2.setAdapter(adapter);