AutoCompleteTextView上的过滤一对一不起作用

时间:2014-01-01 11:02:04

标签: java android autocomplete android-arrayadapter autocompletetextview

您好我正在使用两个autoCompleteTextView州和城市。这里CITY过滤并根据所选状态显示。但是当我保存文本并来自onResume时。 在这里我遇到一个问题,如果STATE被更改,那么没有CITY它接受它不应该的值。这是我的代码:

//state
actv_state.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long rowId) {
ld_state = actv_state.getText().toString();
cityarray = mDbHelper.getCity(ld_state);
ArrayAdapter<String> mp_city_adapter = new ArrayAdapter<String>(
CreateLead.this, android.R.layout.select_dialog_item,cityarray);
actv_city.setThreshold(1);
actv_city.setAdapter(mp_city_adapter);
//city
actv_city.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
ld_city = actv_city.getText().toString();
}});}});

//
actv_state.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
ld_state = actv_state.getText().toString();
for (int i = 0; i < statearray.size(); i++) {
if (ld_state.equals(statearray.get(i))) {
count = 1;
break;
} else {
count = 0;
}
}

// city
actv_city.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
ld_state = actv_state.getText().toString();
ld_city = actv_city.getText().toString();
cityarray = mDbHelper.getCity(ld_state);
for (int i = 0; i < cityarray.size(); i++) {
if (ld_city.equals(cityarray.get(i))) {
ccount = 1;
break;
} else {
ccount = 0;
}
}
}
});

0 个答案:

没有答案