2013-03-20 136 views
1

朋友。將腳註添加到列表視圖時出現問題。我已經使用下面的代碼來添加footerview。將footerview添加到列表視圖

TextView totalIncome = new TextView(this); 
TextView totalExpense = new TextView(this); 
totalIncome.setGravity(Gravity.CENTER); 
totalExpense.setGravity(Gravity.CENTER); 
totalIncome.setPadding(0, 5, 0, 5); 
totalExpense.setPadding(0, 5, 0, 5); 
totalIncome.setText("Total Income is : " + tIncome + ""); 
totalExpense.setText("Total Expense is : " + tExpense + ""); 
final ListView lv1 = (ListView) findViewById(R.id.ListView); 
lv1.addFooterView(totalIncome); 
lv1.addFooterView(totalExpense); 
lv1.setAdapter(adapter); 

但我的問題是,當動態地改變列表內容的footerview下降了一些步驟。我不是爲什麼它在移動。請幫助我的朋友。

對於裁判:

enter image description here

改變內容

enter image description here

看到列表footerview朋友之間的差距後。我不想要這個空間。我在嘗試更改內容時刪除了footerview。但我不能。我通過互聯網搜索了很多。但我沒有找到任何解決方案的朋友。請幫忙。提前致謝。

+0

如果添加另一個數據,頁腳視圖會向下移動? – 2013-03-20 05:44:21

回答

1

1。刪除頁腳視圖

再是ListView的方法去除FooterView

lv.removeFooterView(v); 

你只需要照顧,你是傳遞已添加相同的觀點,這意味着節省totalIncometotalExpense TextView的對象,使他們static和在時間去除通過相同。

2.要刪除空格

沒有把握,還是它的工作。

我想,這就是因爲一旦你將頁眉/頁腳設置爲列表視圖,然後將適配器設置爲列表視圖,頁眉/頁腳視圖被放置在它們的位置並且在修改列表內容時這些視圖不會被改變,建議:嘗試在調用適配器的notifyDatasetChanged方法時再次刪除並添加視圖。

2

我想你可以嘗試刪除並重新進行添加頁腳視圖當您更改列表視圖的內容

刪除:

lv1.removeFooterView(totalIncome); 
lv1.removeFooterView(totalExpense); 

來重新進行添加

lv1.addFooterView(totalIncome); 
lv1.addFooterView(totalExpense);