我有3个Spinners citySpinner,regionSpinner,branchSpinner,我能够填充Spinners中的数据。问题是,如果我从spinnerRegion中选择了UP,则在citySpinner中我只想只显示与该地区相关的城市。请帮助我。

在arraylist中,我现在成功存储了数据,如何根据微调框的选择比较该数据?

 ArrayList<HashMap<String, String>> formList = new ArrayList<HashMap<String, String>>();
            final HashMap<String, String> m_li;
            m_li = new HashMap<String, String>();
            m_li.put("region", region);
            m_li.put("city", city);
            m_li.put("Branch", branch);
            formList.add(m_li);
            Log.d("DDDD----->", String.valueOf(formList));

最佳答案

在您的活动中使用它:

并请使用以下此类代码替换您城市的来源:

    final String JsonData = "[ { \"Br.Name\": \"A BRANCH\", \"Region\": \"UP(W)\", \"City\": \"Agra\" }, { \"Br.Name\": \"B BRANCH\", \"Region\": \"UP(W)\", \"City\": \"Bareilly\" }, { \"Br.Name\": \"C\", \"Region\": \"UP(W)\", \"City\": \"Baghpat\" }, { \"Br.Name\": \"D\", \"Region\": \"UP(E)\", \"City\": \"Amhat\" }, { \"Br.Name\": \"SE\", \"Region\": \"UP(E)\", \"City\": \"Bankeyganj\" }, { \"Br.Name\": \"F\", \"Region\": \"UP Central\", \"City\": \"HARDOI\" }, { \"Br.Name\": \"G\", \"Region\": \"UP(W)\", \"City\": \"Ghaziabad\" } ] ";
    spRegion = findViewById(R.id.spRegion);
    spCity = findViewById(R.id.spCity);


    spRegion.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ArrayAdapter<String> CityAdapter = new ArrayAdapter<String>(Main2Activity.this, R.layout.support_simple_spinner_dropdown_item, getCity(JsonData, spRegion.getSelectedItem().toString()));
            spCity.setAdapter(CityAdapter);
        }

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

        }
    });

关于android - 如何根据其他微调框选择过滤微调框?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49104132/

10-10 00:06