我正在使用 Android Studio 開發 Android 應用程式,但我遇到了下一個問題:這是我的螢屏,無需搜索任何內容。
螢屏
我第一次搜索某些東西時效果很好,但是當我再次搜索時,它會重復我的值。
首次搜索
第二次搜索 - 重復結果
這是我呼叫我的主機并使用我的配接器時的代碼:
cliente.post(URL, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
if (statusCode == 200) {
try {
JSONArray jsonArray = new JSONArray(new String(responseBody));
for (int i = 0; i < jsonArray.length(); i ) {
nombreRepuestoList.add(jsonArray.getJSONObject(i).getString("DESCRIPCION"));
referenciaRepuestoList.add(jsonArray.getJSONObject(i).getString("REFERENCIA_REPUESTO"));
}
ArrayAdapter adaptermaquina = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_2, android.R.id.text1, nombreMaquinaList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
text1.setText(nombreMaquinaList.get(position));
text2.setText(referenciaMaquinaList.get(position));
return view;
}
};
adaptermaquina.notifyDataSetChanged();
listaResultado.setAdapter(adaptermaquina);
} catch (JSONException e) {
e.printStackTrace();
}
我需要一些幫助。
我嘗試使用一個空的配接器,但它不起作用并且使用listaResultado.clear()兩者都不起作用。
uj5u.com熱心網友回復:
不需要清除 adataapter 只需清除串列值
nombreRepuestoList.clear();
referenciaRepuestoList.clear();
在你的代碼中
if (statusCode == 200) {
nombreRepuestoList.clear();//1st
referenciaRepuestoList.clear();//2nd
try {
JSONArray jsonArray = new JSONArray(new String(responseBody));
for (int i = 0; i < jsonArray.length(); i ) {
nombreRepuestoList.add(jsonArray.getJSONObject(i).getString("DESCRIPCION"));
referenciaRepuestoList.add(jsonArray.getJSONObject(i).getString("REFERENCIA_REPUESTO"));
}
我希望這個對你有用
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330514.html
