Reputation: 3646
i use a viewpager with 3 fragments as pages. The first fragment has a listview & a listview header. I add the listview header like so:
View headerView; //defined at the beggining of the class
if (headerView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
//item layout
int viewID = R.layout.listview_header;
headerView = mInflater.inflate(viewID, null);
}
listView.addHeaderView(headerView);
The problem is that when i swipe between the pages and then come back to the first fragment(with the listview header), the header is dublicated(x2 the header views).
I understand that when the viewpager recreates the first fragment it add a second time the header. How can i avoid this?
Upvotes: 0
Views: 820
Reputation: 1537
private void addHeader() {
View header = getActivity().getLayoutInflater().inflate(R.layout.header, null);
TextView tvValue = (TextView) header.findViewById(R.id.tvHeader);
tvValue.setText("Leads");
tvValue.setTextColor(Color.parseColor("#fffb8900"));
getListView().addHeaderView(header,null,false);
}
Upvotes: 1