第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在刷新時重新加載之前清除列表視圖

在刷新時重新加載之前清除列表視圖

函數(shù)式編程 2023-03-09 15:01:47
我有一個列表視圖,我從 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");
查看完整描述

1 回答

?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個贊

替換您的以下代碼

 mSwipeRefreshLayout.post(new Runnable() {                                         @Override
                                         public void run() {

                                             mSwipeRefreshLayout.setRefreshing(true);
                                             mExampleList.clear();
                                             mExampleAdapter.notifyDataSetChanged();
                                             parseJSON();
                                         }
                                     }
            );

updateListContent();
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {            @Override
            public void onRefresh() {
               updateListContent();
            }
        });
    }

創(chuàng)建一個方法來將數(shù)據(jù)更新到列表中:

   public void updateListContent() {
    mSwipeRefreshLayout.setRefreshing(true);    if(mExampleList != null)
      mExampleList.clear();
     parseJSON();
    }


查看完整回答
反對 回復(fù) 2023-03-09
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號