I’m having problems with my List view – I’m trying to add a header view and footer view, but they both seem to appear at the top and bottom of the list. Also, when I scroll, the app freezes for a few seconds.
Here’s my code:
LayoutInflater inflater = getLayoutInflater();
View header = inflater.inflate(R.layout.header_row, (ViewGroup) findViewById(R.id.header_layout_root));
header.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent();
i.setClassName("com.visualdenim.schooltraq", "com.visualdenim.schooltraq.Add_Class");
startActivity(i);
}});
getListView().addHeaderView(header, null, true);
LayoutInflater footerinflater = getLayoutInflater();
View footer = footerinflater.inflate(R.layout.footer_row, (ViewGroup) findViewById(R.id.header_layout_root));
getListView().addFooterView(footer, null, false);
classes = new ArrayList<Course>();
this.cla = new CLA(this, R.layout.row, classes);
setListAdapter(this.cla);
cla.notifyDataSetChanged();
Best answer will be ticked!
Look at the docs for LayoutInflater.inflate():
And then look at the following lines in your code:
…
The views returned in both of these cases will be the same; the
header_layout_rootview contains both the header and the footer and so you will see both at the top and bottom. Inflating the views with a null root and adding them will hopefully fix your problem.There is also no need to use ‘separate’ layout inflaters for the header and footer.