我有一個列表視圖,我從 JSON 填充它。我已經(jīng)應(yīng)用 Swiperefresh 布局來再次清除和重新填充列表視圖。但我的問題是,它不是清除舊項(xiàng)目,而是在舊項(xiàng)目的底部增加新的價值。但我想完全清除所有內(nèi)容,然后從頭開始添加新值。這是我的代碼 mSwipeRefreshLayout.post(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(true); mExampleList.clear(); mExampleAdapter.notifyDataSetChanged(); parseJSON(); } } ); } } private void parseJSON() { String url = getIntent().getStringExtra(EXTRA_URL); JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { myProgressBar.setVisibility(View.GONE); try { JSONArray jsonArray = response.getJSONArray("hits"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject hit = jsonArray.getJSONObject(i); String videoTitle = hit.getString("title"); String link = hit.getString("link"); // String notes = hit.getString("notes"); // String question = hit.getString("question");// String imageUrl = hit.getString("webformatURL");// int likeCount = hit.getInt("likes");
在刷新時重新加載之前清除列表視圖
函數(shù)式編程
2023-03-09 15:01:47