Gunaseelan
Gunaseelan

Reputation: 15535

adding footerview to the listview

Friends. Problem in adding footerview to the listview. I have used the following code to add 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);

But My problem is while changing the list content dynamically the footerview goes down for some steps. I don't why it is moving. Please help me friends.

For ref:

enter image description here

After changing the content

enter image description here

see the gap in between list to footerview friends. I didn't want this space. I tried to removefooterview while changing content. But I can't. I have searched lot through internet. But I didn't find any solution friends. Please help. Thanks in advance.

Upvotes: 1

Views: 844

Answers (2)

MKJParekh
MKJParekh

Reputation: 34301

1. To Remove Footer View

There is a method of ListView to remove FooterView,

lv.removeFooterView(v);

You only need to take care that you are passing the same view which you have added, that means save totalIncome and totalExpense textview objects, make them static and at time to remove pass the same.

2. To Remove the Space

Not Sure, still working on it.

I guess, that's happening as once your have set header/footer to listview and then set adapter to listview, header/footer views get placed at their place and while modifying your list content those views will not get changed, Suggestion : Try removing and adding views again when you call notifyDatasetChanged method for adapter.

Upvotes: 1

Niko Adrianus Yuwono
Niko Adrianus Yuwono

Reputation: 11122

I guess you can try to remove and readd the footer view when you change the content of the listview

to remove :

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

to readd

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

Upvotes: 2

Related Questions