清除微调器项目中的所有列表

时间:2016-09-25 10:22:39

标签: android arrays arraylist spinner

我已经尝试了这个代码,但是一个数组列表会清楚但第二个数据不清楚请给我解决方案在第一个微调器清除微调器2数据但旋转器2不能清除第三个微调器数据请告诉我解决方案

我的数组列表

 private ArrayList<String> students;
    private ArrayList<String> teachers;
    private ArrayList<String> CastName;
    private ArrayList<String> SubCastName;

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

            spinnerreligiontext.setText(getNames(position));
            stst = spinnerreligiontext.getText().toString();
            System.out.println(getNames(position));
            SubCastName.clear();
            CastName.clear();


            CastName();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });


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

            aaa = getNamess(position);
            System.out.println("spin2"+getNamess(position));
            SubCastName.clear();

            SubCastName();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });  spinner3.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            aaa = getSubNamess(position);

            System.out.println("spin3"+getSubNamess(position));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

设置适配器代码

 for (int i = 0; i < j.length(); i++) {
            try {

                //Getting json object
                JSONObject json = j.getJSONObject(i);

                //Adding the name of the student to array list
                students.add(json.getString("AllInOne"));


            } catch (JSONException e) {
                e.printStackTrace();
            }
        }


        spinner1.setAdapter(new ArrayAdapter<String>(RagistarActivity.this, android.R.layout.simple_spinner_dropdown_item, teachers));

1 个答案:

答案 0 :(得分:1)

由于您使用四个数组来填充微调器,您可以通过.clear()方法清除它,所以

students.clear();
teachers.clear();
CastName.clear();
SubCastName.clear();

否则,您可以在需要清除微调器项目时将适配器设置为null