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

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

調(diào)用notifyDataSetChanged()后如何在列表視圖中設(shè)置文本

調(diào)用notifyDataSetChanged()后如何在列表視圖中設(shè)置文本

BIG陽 2021-05-02 08:09:42
方案:我有一個ListView,當(dāng)用戶單擊孩子時,它通過主要活動在ListView內(nèi)設(shè)置TextView的值。我有一個FloatingActionButton,它添加和減去一個對象以計算ListView中的項目數(shù)量。要增加或減少ListView顯示的子項數(shù)量,我致電notifyDataSetChanged()。我正在嘗試設(shè)置在調(diào)用后輸入回TextView的文本notifyDataSetChanged()問題: notifyDataSetChanged()完成運(yùn)行后,將TextView重置為空白。我嘗試過的事情:我嘗試將ListView項目中的所有值保存到單獨(dú)String[] savedItems的文件中,并在TextView中設(shè)置文本。我已經(jīng)在調(diào)試器中逐步運(yùn)行了代碼,看到代碼正在保存文本并實際設(shè)置文本,但是由于某種原因,notifyDataSetChanged()它尚未完成其工作。notifyDataSetChanged()完成后如何設(shè)置文字?有問題的代碼:public void addNewThought(int numberOfThoughts) {    String[] savedDistortionsList = saveDistortions(); // This saves each childs text    selectedItems[numberOfThoughts] = new ArrayList<String>();    IntegerNumberOfThoughts.add(Integer.toString((numberOfThoughts++)) ); // Just the variable that counts the number of children needed in ListView    distortionsAdapter.notifyDataSetChanged(); // Refresh ListView    setBackDistortionsList(savedDistortionsList); // Put back text into ListView}saveDistortions()有效,所以我認(rèn)為沒有必要顯示,但是這里是setBackDistortionsList()我測試過的代碼,它實際上是在ListView中設(shè)置TextView,但是由于某種原因它沒有顯示。setBackDistortionsListprivate void setBackDistortionsList(String[] savedDistortionsList) {    View tempView;    TextView tempTextView;    for (int i = 0; i < savedDistortionsList.length; i++) {        tempView = LDistortions.getChildAt(i);        tempTextView = (TextView) tempView.findViewById(R.id.textEntry);        tempTextView.setText(savedDistortionsList[i]);    }}
查看完整描述

1 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗 獲得超11個贊

在這里找到了答案: 如何檢查ListView完成重繪的時間?

從用戶@Petro復(fù)制并粘貼

希望這可以幫助:

  • 在列表視圖上設(shè)置一個addOnLayoutChangeListener

  • 調(diào)用.notifyDataSetChanged();

  • 完成后,這將觸發(fā)OnLayoutChangeListener

  • 刪除監(jiān)聽器

  • 執(zhí)行更新代碼(getLastVisiblePosition()

mListView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {


  @Override

public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {

    mListView.removeOnLayoutChangeListener(this);

    Log.e(TAG, "updated");

  }

});


mAdapter.notifyDataSetChanged();


查看完整回答
反對 回復(fù) 2021-05-12
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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