Java 如何在连接到ArrayAdapter的AutoCompleteTextView中重置筛选<;字符串>;
我正努力在AutoCompleteTextView中进行自动筛选。 简而言之,我将两个不同的AutoCompleteTextView设置为同一个ArrayAdapter 现在,当我通过在“自动完成”中键入并过滤来选择一个项目,然后跳转到第二个“自动完成”并单击它时,它只显示在上一个“自动完成”中过滤的项目Java 如何在连接到ArrayAdapter的AutoCompleteTextView中重置筛选<;字符串>;,java,android,android-arrayadapter,autocompletetextview,Java,Android,Android Arrayadapter,Autocompletetextview,我正努力在AutoCompleteTextView中进行自动筛选。 简而言之,我将两个不同的AutoCompleteTextView设置为同一个ArrayAdapter 现在,当我通过在“自动完成”中键入并过滤来选择一个项目,然后跳转到第二个“自动完成”并单击它时,它只显示在上一个“自动完成”中过滤的项目 ... ArrayAdapter<String> arrayAdapterMesta; ArrayList<Strin
...
ArrayAdapter<String> arrayAdapterMesta;
ArrayList<String> arrayListMesta = new ArrayList<>();
...
mMestoIstovara_autotext = (AutoCompleteTextView) layout.findViewById(R.id.editMestoIstovara);
mMestoUtovara_atuotext = (AutoCompleteTextView) layout.findViewById(R.id.editMestoUtovara);
....
JSONArray jsonArrayFirmeMesta = new JSONArray(Utility.getPrefsValue(this, Constants.SHAREDPREFS_SIFARNIK_MESTA));
for (int i = 0; i < jsonArrayFirmeMesta.length(); i++) {
JSONObject jsonObject = jsonArrayFirmeMesta.getJSONObject(i);
String client = jsonObject.getString("client");
String mesto = jsonObject.getString("place");
if (!arrayListFirme.contains(client))
arrayListFirme.add(client);
if (!arrayListMesta.contains(mesto))
arrayListMesta.add(mesto);
}
arrayAdapterFirme = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, arrayListFirme);
arrayAdapterMesta = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, arrayListMesta);
if (mMestoIstovara_autotext != null) {
mMestoIstovara_autotext.setAdapter(arrayAdapterMesta);
mMestoIstovara_autotext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMestoIstovara_autotext.showDropDown();
}
});
mMestoIstovara_autotext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (mMestoIstovara_autotext.getText().length() > 0) {
mMestoIstovara_autotext.setTypeface(Typeface.DEFAULT_BOLD);
mMestoIstovara_autotext.setText(mMestoIstovara_autotext.getText().toString().toUpperCase());
} else
mMestoIstovara_autotext.setTypeface(Typeface.DEFAULT);
}
});
}
if (mMestoUtovara_atuotext != null) {
//arrayAdapterMestoUtovara = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, getStringArray(jsonMestoUtovara));
mMestoUtovara_atuotext.setAdapter(arrayAdapterMesta);
mMestoUtovara_atuotext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mMestoUtovara_atuotext.showDropDown();
}
});
mMestoUtovara_atuotext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (mMestoUtovara_atuotext.getText().length() > 0) {
mMestoUtovara_atuotext.setTypeface(Typeface.DEFAULT_BOLD);
mMestoUtovara_atuotext.setText(mMestoUtovara_atuotext.getText().toString().toUpperCase());
} else
mMestoUtovara_atuotext.setTypeface(Typeface.DEFAULT);
}
});
}
。。。
ArrayAdapter arrayAdapterMesta;
ArrayList ArrayListEsta=新的ArrayList();
...
mMestoIstovara_autotext=(AutoCompleteTextView)layout.findViewById(R.id.editMestoIstovara);
mmestotovara_atuotext=(AutoCompleteTextView)layout.findviewbyd(R.id.editmestotovara);
....
JSONArray jsonArrayFirmeMesta=新的JSONArray(Utility.getPrefsValue(this,Constants.SHAREDPREFS\u SIFARNIK\u MESTA));
for(int i=0;i0){
mMestoIstovara_autotext.setTypeface(Typeface.DEFAULT_BOLD);
mmestostovara_autotext.setText(mmestostovara_autotext.getText().toString().toUpperCase());
}否则
mMestoIstovara_autotext.setTypeface(Typeface.DEFAULT);
}
});
}
if(mmestootuovara_atuotext!=null){
//arrayAdapterMestoUtovara=新的ArrayAdapter(这是android.R.layout.simple_下拉列表_item_1line,getStringArray(jsonMestoUtovara));
mmestootuovara_atuotext.setAdapter(ArrayaDaptersta);
mmestootuovara_atuotext.setOnClickListener(新视图.OnClickListener()){
@凌驾
公共void onClick(视图v){
mmestootuovara_atuotext.showDropDown();
}
});
mmestootuovara_atuotext.setOnFocusChangeListener(新视图.OnFocusChangeListener()){
@凌驾
public void onFocusChange(视图v,布尔hasFocus){
if(mmestootuovara_atuotext.getText().length()>0){
mmestootuovara_atuotext.setTypeface(Typeface.DEFAULT_BOLD);
mmestootuovara_atuotext.setText(mmestootuovara_atuotext.getText().toString().toUpperCase());
}否则
mmestootuovara_atuotext.setTypeface(Typeface.DEFAULT);
}
});
}
这是正常行为,您需要两个adapters@pskink谢谢,我用两个不同的适配器解决了这个问题。