私はサーバーからデータをロードするのにVolleyを使用しますが、データをリフレッシュ(リロード)しようとすると問題が発生します。リストビューでは2倍になります。ボタンを5回すばやくクリックすると、5回のデータが取得されます。リストビュー(Volley)を正しくリフレッシュするには?
新しいリフレッシュを開始する前に、最初のロードを停止するにはどうすればよいですか?
私はいつかこのエラーを取得する理由は次のとおりです。 致命的な例外:メイン プロセス:com.project1.proj、PID:19495 java.lang.IndexOutOfBoundsException:インデックス:25、サイズ:0
public void Load_data(View view) {
Load_data();
}
public void Load_data() {
URL="http://myweb.com/data.php;
listItems_001.clear(); // empty the old data
requestQueue = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, URL,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// textView.setText("");
try {
JSONArray jsonArray = response.getJSONArray("all_data");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject respons = jsonArray.getJSONObject(i);
// String id = respons.getString("id") + "*";
String id = respons.getString("id");
name = respons.getString("name");
listItems_001.add(new listItems(id, name));
int request_id = Integer.valueOf(id);
if(request_id > id_last_request){
id_request_now=request_id;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
listAllIteme_001(); // step 10
if (listView.getAdapter().getCount() == 0) {
textView.setVisibility(View.VISIBLE);
listView.setEmptyView(textView);
Toast.makeText(Ordered_Taxi_Driver.this,"No Message found ", Toast.LENGTH_LONG).show();
ly_progressbar_load.setVisibility(View.GONE);
}else{
Toast.makeText(Ordered_Taxi_Driver.this,"Total Items = "+listView.getAdapter().getCount(), Toast.LENGTH_LONG).show();
textView.setVisibility(View.GONE);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("VOLLEY", "ERROR");
}
}
);
requestQueue.add(jsonObjectRequest);
}
を
コード内のIndexOutOfBoundsException-Lineはどこですか? –