NotifyDataSetChanged在android中使用autocompletetextview无法在arraylist中工作

时间:2017-01-11 05:41:46

标签: android android-studio arraylist android-arrayadapter

我想根据autocompletetextview中的国家/地区类型更新州名单。我使用了下面的代码。它第一次正常工作。我写国家但是一旦我编辑了国家名称。它没有更新状态列表(使用notifyDataSetChanged但它不起作用)。请检查代码。谢谢!

 AutoCompleteTextView country_edit,state_edit;

  for (int i = 1; i < global.getExcel().length; i++) {
        String[] separated = global.getExcel()[i].split(",");
        code = separated[0]; // this will contain "Fruit"
        country = separated[1];
        Log.e("length", code + "==" + country);
        Log.e("sep", separated + "====" + global.getExcel()[i]);
        countrylist.add(country);
        codelist.add(code);
        Log.e("countrylist", countrylist + "==");
    }

// ============================================= = ArrayAdapter Country&amp;状态

   final ArrayAdapter<String> country_adapter = new ArrayAdapter<String>
            (this, R.layout.custom_autolistview_list, R.id.text1, countrylist);
    country_edit.setThreshold(1);
    country_edit.setAdapter(country_adapter);


       final ArrayAdapter<String> state_adapter = new ArrayAdapter<String>
            (this, R.layout.custom_autolistview_list, R.id.text1, State_array);
    state_edit.setThreshold(1);
    state_edit.setAdapter(state_adapter);
    state_edit.setDropDownHeight(WRAP_CONTENT);
    state_adapter.notifyDataSetChanged();

  country_edit.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


            //   Log.e("country", country_edit.getText().toString());
            country_str = country_edit.getText().toString();
            //  Log.e("country", country_str);
            int index = countrylist.indexOf(country_str);
            Log.e("index", index + "");
            String code_index = codelist.get(index);
            Log.e("code", code_index);
            State_list.clear();
            State_array.clear();
            for (int i = 0; i < global.getState().length; i++) {


                if (global.getState()[i].contains("," + code_index + ",")) {
                    String statelist = global.getState()[i];
                    Log.e("statelist", statelist);

                    State_list.add(statelist);

                    Log.e("State", State_list + "");
                    state_name = "";
                    for (int j = 0; j < State_list.size(); j++) {
                        String[] statelist_array = State_list.get(j).split(",");
                        state_name = statelist_array[0];
                        String state_code = statelist_array[1];
                        Log.e("state_code", state_code);
                        Log.e("state_name", state_name);

                    }
                    Log.e("Stateeeeeeeee", State_array + "");
                    State_array.add(state_name);
                    Log.e("Stateeeeeeeeeeeeeeee", State_array + "");


                }
                state_ll.setVisibility(View.VISIBLE);

            }
            state_adapter.notifyDataSetChanged();


        }
    });

0 个答案:

没有答案